- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script loop help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 01:40 AM
06-10-2005 01:40 AM
i need urgent help about a script that i have
written...
in script i want to go loop for to find a specific strings in another file and if i find the string then want to remove some files
and exit from loop
All replies will be submitted points!!!
Thank's
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 01:44 AM
06-10-2005 01:44 AM
Re: script loop help
here is my transfer script...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 01:44 AM
06-10-2005 01:44 AM
Re: script loop help
find /start_dir -exec grep "string to look for" |xargs rm
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 01:45 AM
06-10-2005 01:45 AM
Re: script loop help
Code something like:
MAX_EST_TIME=120
#
# Loop until the establish is complete or times out.
#
count=1
_ret=1
while [ $count -le $MAX_EST_TIME -a $_ret != 0 ]
do
sleep 60
# your code
for i in `grep $STRING /somefile`
do
rm $FILE1
exit 1
done
done
or something like that...
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 01:48 AM
06-10-2005 01:48 AM
Re: script loop help
find /start_dir -exec grep "string to look for" {} \; |xargs rm
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 01:50 AM
06-10-2005 01:50 AM
Re: script loop help
while read -r
do
# code
done < input_file #lists the files to be processed, can be created by Pete's find command.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 01:52 AM
06-10-2005 01:52 AM
Re: script loop help
if you look my script i do not want to use
sleep command...it is a transfer script
i mean i have a transfer program called
RVS and it is also screen oriented but i do not use..i have put the script and run as root from cron..i have many transfers scripts
with rvs and always run from root cron...
When a file succesfully transfer it saves
in rlstat.log file which belongs to user
RVs...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 01:55 AM
06-10-2005 01:55 AM
Re: script loop help
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 01:57 AM
06-10-2005 01:57 AM
Re: script loop help
to exit from a loop you can use break
while :
do
if [ -f /tmp/toto ]
then
rm /tmp/toto
break
fi
sleep 500
done
or with a function
function testandremove
{
if [ -f /tmp/toto ]
then
rm /tmp/toto
return 1
fi
return 0
}
while testandremove
do
sleep 600
done
or
while :
do
testandremove
if [ $? == 0 ]
then
break
fi
sleep 600
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 01:58 AM
06-10-2005 01:58 AM
Re: script loop help
i am really bat at scripting...Please
take a look of my script and maybe the
3rd eyes can see or maintain my script
so i need your guide...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 02:07 AM
06-10-2005 02:07 AM
Re: script loop help
if [ -f ${time_chk_f_crt}_TFBUCH1C.100.txt ]
...
fi
if [ -f ${time_chk_f_crt}_TFBUCH1C.300.txt ]
...
fi
if [ -f ${time_chk_f_crt}_TFBUCH1C.500.txt ]
...
fi
down to a more manageable "loop" (basically detecting and processing 100 300 500 etc)? Then I would recommend something like: -
for FILE in ${time_chk_f_crt}_TFBUCH1C.100.txt
do
NUM=`cut -d. -f2`
/users/rvs/system/rvsut2fv $DIR1/${time_chk_f_crt}_TFBUCH1C.$NUM.txt.rvs F 650 $DIR1/${time_chk_f_crt}_TFBUCH1C.$NUM.txt T
echo "SEND DSN=\"$DIR1/${time_chk_f_crt}_TFBUCH1C.$NUM.txt.rvs\" FORMAT=F (SID=MAN CODEOUT=A DSNNEW=$FILENEW)" >$DIR1/TFBUCH1C.$NUM.rvs.tmp
/users/rvs/system/rvsbat /i$DIR1/TFBUCH1C.$NUM.rvs.tmp
sleep 600;
egrep -i ${time_chk_f_crt}_TFBUCH1C.$NUM.txt.rvs /users/rvs/db/rlstat.log
if [ $? = 0 ]
then
echo $DIR1/${time_chk_f_crt}_TFBUCH1C.$NUM.txt.rvs succesfully SEND... `date`>>$DIR0/rvs_sap_send_log
rm -Rf *.$NUM.rvs.tmp
rm -Rf *.$NUM.txt.rvs
rm -Rf *.$NUM.rcp
rm -Rf *.$NUM.txt
rm -Rf *.$NUM
else
echo $DIR1/${time_chk_f_crt}_TFBUCH1C.$NUM.txt.rvs is WAITING!!!or RVS Error!!! `date`>>$DIR0/rvs_err_log
fi
done
This assumes that your variable ${time_chk_f_crt} has no "." characters in, otherwise you'll have to change the cut command accortingly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 02:10 AM
06-10-2005 02:10 AM
Re: script loop help
for FILE in ${time_chk_f_crt}_TFBUCH1C.*.txt
do
NUM=`echo $FILE | cut -d. -f2`
Basically what it's doing is looping for each file that matches (TFMUCH1C.100, 300, 500 etc.) and using the cut to get the number portion as variable $NUM. This is then used in the rest of the loop code in place of .100. in your rm's, calls to rvs code etc.
Hope this makes sense?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 02:17 AM
06-10-2005 02:17 AM
SolutionSome nice answers
For scripting I always check
www.shelldorado.com
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 02:25 AM
06-10-2005 02:25 AM
Re: script loop help
i know i do not have loop but i need loop.
As you seen my script;
i have a directory and there are some files
waiting to transfer somewhere (out of country)
now the rules are;
the files only *.rcp extension are ready
to transfer...
let's say in diretory;
DVA.E04MAN.TFBUCH1C.100
DVA.E04MAN.TFBUCH1C.100.rcp
so this means DVA.E04MAN.TFBUCH1C.100 must
be transferred but before transfering
i have to convert this original file
(you see in my script)
/users/rvs/system/rvsut2fv $DIR1/${time_chk_f_crt}_TFBUCH1C.100.txt.rvs F 650 $DIR1/${time_chk_f_crt}_TFBUCH1C.100.txt T
echo "SEND DSN=\"$DIR1/${time_chk_f_crt}_TFBUCH1C.100.txt.rvs\" FORMAT=F (SID=MAN CODEOUT=A DSNNEW=$FILENEW)" >$DIR1/TFBUCH1C.100.rvs.tmp
/users/rvs/system/rvsbat /i$DIR1/TFBUCH1C.100.rvs.tmp
so transfers starts...
Now the trick is here
i have to check whether transfer succesfully
finish or not!!!! so
the control file is rlstat.log which after
transfers save in here and this file have records like;
$ pwd
/users/rvs/db
$ cat rlstat.log|tail -3
R MAN 566182 566187 2005/06/10 15:17:37 DVA.MANE04.MLLC2 /users/rvs/usrdat/taxxxxxx/taxxxxxx.T162149 4623
S MAN 566202 566203 2005/06/10 16:30:08 DVA.E04MAN.TFBUCH1C /sap/TFBUCH1C/2005_06_10_1630_TFBUCH1C.300.txt.rvs 1987
S MAN 566221 566222 2005/06/10 17:00:05 DVA.E04MAN.FAVE /users/rvs/usrdat/fave_gidecek_tmp/fave061005151902.txt.rvs 292
SO that's why i use egrep -i
Now the most important point is the files
are approx 300MB and that's why i use
sleep 600;
but this transfer time may take 20 minutes
and at this time i can not delete the files
because when the transfer is Ok i have to
empty my DIRECTORY...
Now,i how can i set a loop;
When transfer starts and waits,and try to see this file untill in rlstat.log file in my script..this is my problem..and
i think i need a loop...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 02:29 AM
06-10-2005 02:29 AM
Re: script loop help
:-(
thks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 02:35 AM
06-10-2005 02:35 AM
Re: script loop help
while [ "`fuser {time_chk_f_crt}_TFBUCH1C.100.txt.rvs`" != "" ]; do
sleep 60
done
This will use fuser to see if any process has the file open (your file transfer program). If this returns a PID, then the loop will sleep for 60 seconds then test again. It will keep doing this until no process has that file open.
You can then perform your grep to confirm the logfile output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 02:46 AM
06-10-2005 02:46 AM
Re: script loop help
---------
MAXMINUTES=60
grep -iq ${time_chk_f_crt}_TFBUCH1C.$NUM.txt.rvs /users/rvs/db/rlstat.log
while [ $? -ne 0 ]; do
sleep 60
(( MAXMINUTES = MAXMINUTES - 1 ))
if [ $MAXMINUTES -eq 0 ]; then
echo "Maximum transfer time reached!"
exit 1
fi
echo $MAXMINUTES
grep -iq ${time_chk_f_crt}_TFBUCH1C.$NUM.txt.rvs /users/rvs/db/rlstat.log
done
--------
This will keep checking (every minute) for the filename in the log file. Every time it checks, it counts MAXMINUTES down 1. If this reaches zero it errors.
You need the MAXMINUTES in case the script loops forever. This should be what you need.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 03:00 AM
06-10-2005 03:00 AM
Re: script loop help
you seem understood me...
how about this ?
until [ "`cat rlstat.log|egrep -i ${time_chk_f_crt}_TFBUCH1C.100.txt.rvs|awk '{print $8}'|cut -c-15-` = "${time_chk_f_crt}_TFBUCH1C.100.txt.rvs"
do
sleep;
done
echo $DIR1/${time_chk_f_crt}_TFBUCH1C.100.txt.rvs succesfully SEND... `date`>>$DIR0/rvs_sap_send_log
rm -Rf *.100.rvs.tmp
rm -Rf *.100.txt.rvs
rm -Rf *.100.rcp
rm -Rf *.100.txt
rm -Rf *.100
Does it work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2005 05:08 PM
06-13-2005 05:08 PM
Re: script loop help
while true; do
if egrep -i ${time_chk_f_crt}_TFBUCH1C.100.txt.rvs /users/rvs/db/rlstat.log
then
echo $DIR1/${time_chk_f_crt}_TFBUCH1C.100.txt.rvs succesfully SEND... `date`>>$DIR0/rvs_sap_send_log
rm -Rf *.*
break
else
sleep 1
fi