Please help inserting the correct if-then-else statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Please help inserting the correct if-then-else statement
# 1  
Old 11-26-2009
Please help inserting the correct if-then-else statement

Hi All,

I have this script below that checks rpm code version to Linux and Solaris servers.
The script is run using arguement ($1) which is server_list.txt. It runs as:
$ ./scriptname server_list.txt

Code:
#!/bin/bash 

QUERY="/opt/rpm/bin/rpm -qa --queryformat '%{installtime} %{name}-%{version}-%{release}-%{arch} \n'| grep vc |
awk '{ if ( \$1 > '`/usr/local/bin/date -d "1 week ago" +%s`')  print \$2 }'"

QUERY1="rpm -qa --queryformat '%{installtime} %{name}-%{version}-%{release}-%{arch} \n'| grep vc |
awk '{ if ( \$1 > '`date -d "1 week ago" +%s`')  print \$2 }'"

echo "Processing $1..."
LIST=`cat $1`


for i in $LIST
do

OS=`ssh -q root@$i uname -a |grep Linux`

      if [ "$OS" == "" ]
         then
            solaris=`ssh -q root@$i $QUERY`
            if [ "$solaris" != "" ]
               then
                 echo -e "\n$i"
                 echo -e "\n$solaris"
            fi
       else
            linux=`ssh -q root@$i $QUERY1`
            if [ "$linux" != "" ]
               then
                 echo -e "\n$i"
                 echo -e "\n$linux"
            fi
       fi

done

echo -e "\nEnd of Report"

-------

here is the output below:

Code:
adminj.pm.test1.intra

 vc_portal_admin-jp.test1-2.22_MATADOR.8-0-noarch
 xinetd-2.3.14-9.fc6-x86_64

adminj.pm.test2.intra

 vc_portal_admin-jp.test2-2.21.22-0-noarch

My problem is what if the server is out of pull ?
or the server can't be ssh? How will I going to insert the
test ( if else statement ) from the existing code so that
the script will tell that the server is out of pull?

Last edited by Franklin52; 11-26-2009 at 08:47 AM.. Reason: Please use code tags!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

2. Shell Programming and Scripting

Inserting Delimiters

Hi Team, I am trying to get the data in below format Jan 01 | 19:00:32 | xyz | abc | sometext | string however I am not sure of the total number strings which can come in the record hence i cant use something like below as it can end $6 or it can go further cat file| awk... (8 Replies)
Discussion started by: rakesh_411
8 Replies

3. Shell Programming and Scripting

if statement is not giving correct op

Hi I am using a awk command but not getting required o/p. input file a.txt 2 ak 3 cb 4 de 5 gh 6 ij awk program BEGIN { x=0 } {if ($1>3) {x=x+1}{print $0} } END { print "I found " x " line have value more than 3" } output 2 ak 3 cb 4 de 5 gh 6 ij (3 Replies)
Discussion started by: aaysa123
3 Replies

4. Shell Programming and Scripting

::select statement return value with correct field size::

Hi Everyone, I am facing a problem regarding the select from sybase, the return with the incorrect size. For example, field is NAME(20). After i selected from sybase, the result is nicky. after i assign it to another declaration variable, it will be in actual name "nicky" , what i need... (10 Replies)
Discussion started by: ryanW
10 Replies

5. Shell Programming and Scripting

Please correct this

I have input file like this Input file: ABC|abc_etc_passwd XYZ|XYZ_etc_passwd zXY|XYZ_etc_passwd IJK|test_etc_passwd KLM|test_etc_passwd i want to do following in a loop. grep 'ABC' *abc_etc_passwd* grep 'XYZ' *XYZ_etc_passwd* grep 'ZXY' *ZXY_etc_passwd* i have tried this for i... (2 Replies)
Discussion started by: pinnacle
2 Replies

6. Shell Programming and Scripting

inserting lines

Hi I would like to add lines to a file at specific locations. eg: If I have a file containing data... ABC DEF GHIJKLKMNOP RSTUVWXYZ and I have a requirement to insert a lines a) "LINE_FIRST" before first line in the file b) "LINE_X" before third line in the file c) "LINE_LAST"... (2 Replies)
Discussion started by: tostay2003
2 Replies

7. Shell Programming and Scripting

Non-inserting backslash in sed statement

#!/bin/bash wget -O tmp.tmp "YouTube - Pretty Woman- Vivian's Goes Shopping!" temp=`grep 'one&video_id=' tmp.tmp | sed "s/.*one&video_id=\(.*\)'\;.*/\1/"` temp="http://www.youtube.com/get_video?video_id=$temp" temp=`echo $temp|sed -n "s/!/\\!/p"` echo " -O $filename \"$temp\"" Output:... (3 Replies)
Discussion started by: kds1398
3 Replies

8. Shell Programming and Scripting

How is use sselect statement o/p in insert statement.

Hi All, I am using Unix ksh script. I need to insert values to a table using the o/p from a slelect statement. Can anybody Help! My script looks like tihs. ---`sqlplus -s username/password@SID << EOF set heading off set feedback off set pages 0 insert into ${TB_NAME}_D... (2 Replies)
Discussion started by: nkosaraju
2 Replies

9. Shell Programming and Scripting

Need help in inserting a value.........

Hello, I'm having a files with variable no of lines. An example for this file is as follows ~xxx STRT 0.0000000000 : STOP : ~xxxxx 0.000000 557.109552 -557.109552 1511.482910 -954.373377 954.373377 in the STOP line below the 0.00000000000 I need... (8 Replies)
Discussion started by: santyshyam
8 Replies

10. Shell Programming and Scripting

If statement - How to write a null statement

In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands. How do I write the "do nothing" statement in the following example? Example: if (( "$x"="1" && "$y"="a" && "$z"="happy" )) then do nothing else command command fi... (3 Replies)
Discussion started by: april
3 Replies
Login or Register to Ask a Question