I have written a simple move_script to check and move the files from multiple dirs to other dirs and a check_script scheduled via cron every 30 mins to check and runs move_script if it is not running.
The files gets moved without any issues but the script doesn't exits once the move is completed and the cron job i have scheduled finds the script is still in running state and it doesn't do anything.
MOVE SCRIPT :
Code:
#!/bin/sh
while [ Y = Y ]
sleep 600
do
ls -l /Prod/ABC/*txt* > /dev/null 2>&1
if [ $? -eq 0 ]
then
sleep 60
for i in `ls -1 /Prod/ABC/*txt*`
do
echo "Moving file $i to /NFS_share/Prod/ABC/txt" >> /var/log/move_script.log
mv $i /NFS_share/Prod/ABC/txt >> /var/log/move_script.log 2>&1
done
fi
ls -l /Prod/XYZ/*txt* > /dev/null 2>&1
if [ $? -eq 0 ]
then
sleep 60
for i in `/Prod/XYZ/*txt*`
do
echo "Moving file $i to /NFS_share/Prod/XYZ/txt" >> /var/log/move_script.log
mv $i /NFS_share/Prod/XYZ/txt >> /var/log/move_script.log 2>&1
done
fi
ls -l /Prod/ABC/*doc* > /dev/null 2>&1
if [ $? -eq 0 ]
then
sleep 60
for i in `ls -1 /Prod/ABC/*doc*`
do
echo "Moving file $i to /NFS_share/Prod/ABC/doc" >> /var/log/move_script.log
mv $i /NFS_share/Prod/ABC/doc >> /var/log/move_script.log 2>&1
done
fi
ls -l /Prod/XYZ/*doc* > /dev/null 2>&1
if [ $? -eq 0 ]
then
sleep 60
for i in `ls -1 /Prod/XYZ/*doc*`
do
echo "Moving file $i to /NFS_share/Prod/XYZ/docl" >> /var/log/move_script.log
mv $i /NFS_share/Prod/XYZ/doc >> /var/log/move_script.log 2>&1
done
fi
done
CHECK_SCRIPT
Code:
ps -ef |grep move_script.sh |grep -v $$ > /dev/null 2>&1
if [ $? -ne 0 ]
then
nohup /scripts/move_script.sh &
fi
Kindly request to check and advice me on whats wrong with the script. Please let me know how to log the o/p of the scripts along with the time stamp. Also kindly suggest me any better way of doing this tasks as i am new to scripting. Appreciate your response.