For Loop help with patchrm Solaris 10


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting For Loop help with patchrm Solaris 10
# 1  
Old 08-17-2009
For Loop help with patchrm Solaris 10

Hello all

looking to write a for loop to remove patches in the /var/sadm/patch directory. So far this is what i have:

Code:
#! /bin/sh

cd /var/sadm/patch

ls -l | awk '{print $9}' > patches

/usr/bin/sort -r patches > patches_r

for i in 'cat patches_r'
  do 
    echo "going to remove patch $i"

            /usr/sbin/patchrm $i
done

echo "All patches should be removed"

i receive the error when it gets to the for loop. it errors on 'cat patches_r' and claims there is no patch named cat or patches_r?

still new to shell scripting, can someone explain where this is messing up??

Thanks
# 2  
Old 08-17-2009
Use backticks , not single-quote.
Code:
for i in `cat patches_r`
  do 
    echo "going to remove patch $i"

            /usr/sbin/patchrm $i
done

... and don't try to win the Useless Use of Cat Award

Code:
while read i
  do 
    echo "going to remove patch $i"

            /usr/sbin/patchrm $i
done < patches_r

# 3  
Old 08-17-2009
you need to use `and not '. better is to use $(command).
# 4  
Old 08-17-2009
Quote:
Originally Posted by danmero
Use backticks , not single-quote.
Code:
for i in `cat patches_r`
  do 
    echo "going to remove patch $i"

            /usr/sbin/patchrm $i
done

... and don't try to win the Useless Use of Cat Award

Code:
while read i
  do 
    echo "going to remove patch $i"

            /usr/sbin/patchrm $i
done < patches_r


what do you mean the useless use of cat award? Would you suggest using something else?
# 5  
Old 08-17-2009
Quote:
Originally Posted by caddyjoe77
what do you mean the useless use of cat award? Would you suggest using something else?
the second code IS the better solution!
# 6  
Old 08-17-2009
Let's remember what is Useless Use of Cat Award Smilie
# 7  
Old 08-17-2009
Quote:
Originally Posted by danmero
Let's remember what is Useless Use of Cat Award Smilie
wow, ok. Thanks for that bit of UNIX history. Makes sense and i appreciate it. In fact, that entire page is pretty good.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Solaris 10 Login Page Loop

I'm currently logged in as Root on a Solaris 10 Server for my schools department and I'm trying to figure out why 20 of my users(Students) can log into the Solaris 10 Sun Ray Oracle Server with correct username and password but then be looped back to the same log in page. I tried deleting their... (7 Replies)
Discussion started by: mwilliams21z
7 Replies

2. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

3. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

4. Solaris

Solaris 10 Login Loop Problem

I recently installed Solaris 10 as a VM. I was using the JDS and shut down the vm when I left the office. When I rebooted today I login in at the desktop login screen and press ok but I am reverted to the console screen for a spilt second and then back to the login screen. I log in as root and my... (7 Replies)
Discussion started by: mvhoward
7 Replies

5. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

6. Solaris

Problem in for loop of shell scripting in solaris

Hi below is my script for((i=0;i<=$TOTAL;i++)) do echo "IP's created are $s1.$s2.$s3.$s4" s4=`expr $s4 + 1` done where s1,2,3,4 are input varibles below error occurs while running the script syntax error at lin 11: '(' unexpected ... (12 Replies)
Discussion started by: krevathi1912
12 Replies

7. UNIX for Dummies Questions & Answers

patchrm problem

Hello, In order to remove a patch, I type following command; # #patchrm 119314-11 and following error message shown on the screen, the patch can not be removed: Cannot find teh backout packages for 119314-11 119314-11 cannot ve backed out. Patchrm is terminating. WARNING: patchrm... (0 Replies)
Discussion started by: XNOR
0 Replies

8. Solaris

patchadd/patchrm

Ok, I attempted to apply a patch to a V440 and it bailed part way through. When I tried to patchrm the patch (after booting from CD), patchrm said that I had to fully install the failed patch before I could delete it. Since installing it killed the system forcing a boot from CD, it sounds like a... (4 Replies)
Discussion started by: BOFH
4 Replies
Login or Register to Ask a Question