Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to rlogin (rsh) to host of unix servers to find/remove files

Status
Not open for further replies.

arlram

MIS
Jan 13, 2003
8
0
0
US
Please help!!! I am not a good unix scripter and i need a script to use as input a file with unix host names. This scripts will rlogin (rsh) to each host and go to the /var/tmp directory and rm any files older than 7 days.

please help
 
Very quick here...

#! /bin/sh

for host in `cat <name of file with list of hosts>`
do
rsh host find /var/tmp -ctime 7 -exec rm -r {} \;
done


Check the man page for the find command. I cannot remember if this is the exact option and syntax or not, but should be close. The ctime stands for creation date, you may want to use mtime for last modified date. Also, instead of using &quot;-exec rm -r&quot; you can use &quot;-ok&quot; and you will be prompted to verify the deletion of the file. Be sure you are running the script as a user that has the proper permissions to remove files in /var/tmp on the remote machines as well.

Good Luck!! Have a Great Day!! :)
~Sol
Sys Admin
 
Oops, almost forgot... be sure to use the proper rsh... you want remote shell NOT restricted shell. I believe remote shell is /usr/bin/rsh and restricted shell is /usr/lib/rsh... Be sure to check this.
Have a Great Day!! :)
~Sol
Sys Admin
 
Thank you very much... I have something similiar to that but it only processes the first entry the cat file. it does not do the loop....There are 50 entries in .test_info

if [ X$1 = XPROD ]
then
SERVER_TYPE_LIST='PROD'
else
SERVER_TYPE_LIST='BACK'
fi



for SERVER_TYPE in $SERVER_TYPE_LIST
do

cat $HOME/BOFA/.test_info |
while read SERVER MACHINE SA_PASS SYB_PASS TYPE SYB_DIR REP_DIR
do
if [ $TYPE = PROD ]
then
echo $MACHINE
#rsh $MACHINE -l sqladmin $HOME/scripts/deletefile.ksh
rsh $MACHINE find /var/tmp -type f -mtime +7
else
echo $MACHINE
echo $TYPE
echo &quot;not a PROD or BACK machine&quot;
fi
done
done
 
Use rsh -n or else it breaks the while read loop. I was puzzled by that one for ages! Annihilannic.
 
THANK YOU !!! annihilannic!!! i wasted quite a bit of time on this.. thanks again.. great website.. just stumbled upon it.. :) have a great day
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top