Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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?

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.

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 0Script2:
#!/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

![]() |
![]() |
![]() |

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