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.
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 "-exec rm -r" you can use "-ok" 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.
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 "not a PROD or BACK machine"
fi
done
done
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.