LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 02-18-2012, 06:02 PM   #1
sle09
LQ Newbie
 
Registered: Feb 2012
Posts: 1

Rep: Reputation: Disabled
Cool cron problem


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

the .sh files contain


mkdir /home/sle09/ftp/camera/door/`date --date='UTC +4 hours' +\%F_\%R`; find /home/sle09/ftp/door/ -type f -name '*' -exec mv {} $_/. \;

and the other file the same but door is rover

ive been trying to fix this like crazy with no success, thanks
 
Old 02-18-2012, 09:17 PM   #2
uhelp
Member
 
Registered: Nov 2011
Location: Germany, Bavaria, Nueremberg area
Distribution: openSUSE, Debian, LFS
Posts: 205

Rep: Reputation: 43
use a var to for the date:
Code:
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?
 
Old 02-19-2012, 09:32 PM   #3
pafoo
Member
 
Registered: Jul 2011
Location: Alabama
Distribution: Red Hat/Ubuntu/Solaris
Posts: 37

Rep: Reputation: 11
Quote:
Originally Posted by uhelp View Post
use a var to for the date:
Code:
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.

Last edited by pafoo; 02-19-2012 at 09:34 PM.
 
Old 02-20-2012, 03:14 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by pafoo View Post
He is correct. Always, always, ALWAYS use the absolute path of everything unless you cannot avoid it.
Or set and export PATH
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange Cron directories: /var/spool/cron/cron.GfqqGO Woodsman Slackware 4 05-11-2011 02:37 PM
cron.hourly cron.weekly cron.monthly and 0anacron. Are they necessary? glore2002 Debian 2 09-30-2009 08:57 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U SUSE / openSUSE 11 01-04-2007 01:57 AM
Can any one plz explain why/what for cron.d, cron.daily, cron.weekly etc are there. mavinashbabu Linux - Newbie 4 09-21-2006 01:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration