Computing.Net > Forums > Unix > need help in scripting ksh

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

need help in scripting ksh

Reply to Message Icon

Name: ling_k82
Date: January 8, 2006 at 18:50:37 Pacific
OS: unix
CPU/Ram: n/a
Comment:

i am a dummy in ksh now i need to write a script to join a some file, either by joining 50 files to one file, or join the files in one after timeout. can anyone help me out?



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: January 8, 2006 at 20:22:28 Pacific
Reply:

Your question is too vague for me to answer it.


0

Response Number 2
Name: ling_k82
Date: January 8, 2006 at 21:15:48 Pacific
Reply:

so sorry for that.

i actually need to have the xxid.txt file in the log dir join under two condition:
1) when the dir's file reaches 50 files
2) after timeout of maybe 1 min if less than 50 files in that dir.

it's quite tough for me since i never do one before. thanks in advance for the help.


0

Response Number 3
Name: sid
Date: January 22, 2006 at 03:37:50 Pacific
Reply:

Create two process, one will sleep for 60 seconds, then will kill the other process if it exists and join the files and then exit.

The other one will continue to monitor the directory in 2 sec gap, if no of file is more than 50, then join the files, kill the other process and exit.

My suggestion is write two scripts:

Script1:
#!/usr/bin/ksh
rm -f /tmp/Temp.Script1 2>/dev/null
touch /tmp/Temp.Script1
echo $$ > /tmp/Temp.Script1
sleep 60 #I assume one min is timeout
if [ -s /tmp/Temp.Script2 ]
then
kill -9 `cat /tmp/Temp.Script2` 2>/dev/null
cat `ls $logdir` > xxid.txt
fi
exit 0

Script2:
#!/usr/bin/ksh
rm -f /tmp/Temp.Script2 2>/dev/null
touch /tmp/Temp.Script2
echo $$ > /tmp/Temp.Script2
wait=0
Script1 & #In the background
while [ $wait -eq 0 ]
do
no_of_file=$(ls $logdir | wc -l)
if [ $no_of_file -ge 50 ]
then
cat `ls $logdir` > xxid.txt
wait=1
else
sleep 2
fi
done
rm -f /tmp/Temp.Script2 2>/dev/null
if [ -s /tmp/Temp.Script1 ]
then
kill -9 `cat /tmp/Temp.Script1` 2>/dev/null
fi
exit 0


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: need help in scripting ksh

need help in scripting www.computing.net/answers/unix/need-help-in-scripting/8216.html

Replacing a word in a file www.computing.net/answers/unix/replacing-a-word-in-a-file-/7137.html

Need Help with KornShell script www.computing.net/answers/unix/need-help-with-kornshell-script/5978.html