Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i have a hosting account at hostgator running linux and have ssh access and cron via cpanel, i have two security cameras that ftp upload snapshots upon movement and the upload to /home/sle09/ftp/door/ and /home/sle09/ftp/rover/ one for each camera, so the folders both just get alot of snapshots to many to look through, so i made a cron script that basically every hour takes the pictures from each folder and creates a new folder in /home/sle09/ftp/camera/door/ and /home/sle09/ftp/camera/rover/ respectivly naming the folder with the date and time and then moving the pictures into the newly created folder that way every hour will have a different folder and will never have 90,000 pictures to go through over time. i made a door.sh and rover.sh and made the exectutable and called them from ssh command line and it works fine and creates the folder with date and time and moves files, also i set it to run every minute just to test it while i was watching and it worked too. however i set it to everyhour and walked away and when i came back i find that it is running and moving the files from /home/sle09/ftp/door/ to /home/sle09/ftp/camera/door/ but not creating the folder with date and time its just putting the pictues in there so instead of /home/sle09/ftp/camera/door/ havning folders in it, it has picutes, and it did the same for /home/sle09/ftp/camera/rover
doorDate=$( date --date='UTC +4 hours' +'%F_%R'
doorDIR='/home/sle09/ftp/camera/door/'
doorDirNew=${doorDir}${doorDate}'/'
# and finally something like this:
mv * $doorDirNew
$_ Gives the last argument to the previous command. At the shell startup, it gives the absolute filename of the shell script being executed.
So don't use this. What do you expect will happen, when a failure occurs?
He is correct. Always, always, ALWAYS use the absolute path of everything unless you cannot avoid it. Also, you should enter error handling as well. Lets say..
Code:
#!/bin/bash
doorDate=$( date --date='UTC +4 hours' +'%F_%R'
doorDIR='/home/sle09/ftp/camera/door/'
doorDirNew=${doorDir}${doorDate}'/'
if [ ! -d $doorDirNew ]
then
mkdir $doorDirNew
if [ ! -d $doorDirNew ]
then
printf "Failed making new directory %s\n please look in to error" $doorDirNew | mail -s "Error making pic directory" myadmin@adminsrule.net
fi
find $doorDir -type f -cmin -60 -name "*.pic" -exec mv {} $doorDirNew \;
else printf "Directory %s exists, problem with date variable?" $doorDate | mail -s "Error making pic directory" myadmin@adminsrule.net
fi
Even basic scripts work better with SOME level of error handling.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.