LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Please help me write script (https://www.linuxquestions.org/questions/linux-newbie-8/please-help-me-write-script-718830/)

sharp859 04-13-2009 01:27 PM

Please help me write script
 
Hi I need to have a script which lists all rpm files which are modified.

I need to run
rpm -qa | grep NC |xargs rpm -V

out put=
.......T c /etc/logrotate.d/attivio_adb
.......T c /etc/monit.d/monit_common.conf
.......T /opt/cisco/bin/showver.sh
.......T /etc/logrotate.d/attivio
S.5....T c /opt/attivio/conf/log4j.xml
S.5....T /opt/mgmt/scripts/pfile
.......T c /opt/cic/tomcat/conf/tomcat-users.xml

Now I need only files which are modified i.e files look like below

S.5....T c /opt/attivio/conf/log4j.xml
S.5....T /opt/mgmt/scripts/pfile

any body can give a script.


Thanks!
Praveen

custangro 04-13-2009 01:39 PM

Quote:

Originally Posted by sharp859 (Post 3507590)
Hi I need to have a script which lists all rpm files which are modified.

I need to run
rpm -qa | grep NC |xargs rpm -V

out put=
.......T c /etc/logrotate.d/attivio_adb
.......T c /etc/monit.d/monit_common.conf
.......T /opt/cisco/bin/showver.sh
.......T /etc/logrotate.d/attivio
S.5....T c /opt/attivio/conf/log4j.xml
S.5....T /opt/mgmt/scripts/pfile
.......T c /opt/cic/tomcat/conf/tomcat-users.xml

Now I need only files which are modified i.e files look like below

S.5....T c /opt/attivio/conf/log4j.xml
S.5....T /opt/mgmt/scripts/pfile

any body can give a script.


Thanks!
Praveen

There is probably a better way...but out of the top of my head....
Code:

rpm -qa | grep NC |xargs rpm -V | grep '^S'

sharp859 04-15-2009 12:48 PM

Thanks for help.

But I have soem more help I could able to list those files like this using

rpm -qa | grep NC |xargs rpm -V | grep '^S'

S.5....T c /opt/attivio/conf/log4j.xml
S.5....T /opt/mgmt/scripts/pfile
..

Now I need to copy
/opt/attivio/conf/log4j.xml
/opt/mgmt/scripts/pfile
..

so on..
What ever I got listed should copy to another file.

basically
S.5....T c
S.5....T

Should be chomped off and

cp /opt/attivio/conf/log4j.xml /new_directory/
cp /opt/mgmt/scripts/pfile /new_directory/
...

Please let me know how I can go ahead

Thanks in advance.

custangro 04-15-2009 02:17 PM

Quote:

Originally Posted by sharp859 (Post 3509946)
Thanks for help.

But I have soem more help I could able to list those files like this using

rpm -qa | grep NC |xargs rpm -V | grep '^S'

S.5....T c /opt/attivio/conf/log4j.xml
S.5....T /opt/mgmt/scripts/pfile
..

Now I need to copy
/opt/attivio/conf/log4j.xml
/opt/mgmt/scripts/pfile
..

so on..
What ever I got listed should copy to another file.

basically
S.5....T c
S.5....T

Should be chomped off and

cp /opt/attivio/conf/log4j.xml /new_directory/
cp /opt/mgmt/scripts/pfile /new_directory/
...

Please let me know how I can go ahead

Thanks in advance.

If it's always the last field you can use awk....

Code:

rpm -qa | grep NC |xargs rpm -V | grep '^S' | awk '{print $NF}'
-C

sharp859 04-16-2009 05:29 PM

Thanks for help but I used another way to get it done.

#!/bin/bash
#set -x

rpm -qa | grep ^NC | xargs rpm -V | grep ^S > /tmp/changeset.dat

cd /tmp/

cat changeset.dat| while read line
do
cut -b 12- > changeset1.dat
done
for file in `cat changeset1.dat`
do
cp -r $file /tmp/test
done

#Remove temp directory at last
rm -rf changeset.dat changeset1.dat

sharp859 04-16-2009 05:41 PM

Thanks to all
 
Thanks to all, and I figured out to do using cut command and while loop.

Thanks!


All times are GMT -5. The time now is 09:22 AM.