Author |
Message |
divisionmd

Joined: 14 Jul 2007 Posts: 608
|
Posted: Mon 04 Mar 2013, 09:40 Post subject:
Looking for a script that copies files only on Sundays |
|
Hello,
- Anyone handy with bash script can do this:
- from one line: if its sunday -> copy a file from A to B -> if not sunday continue script
easy to do? was thinking of a few crontab methods but interesting to hear what other smart ways there is to do this?
Thanks,
Best regards,
Johan
|
Back to top
|
|
 |
GustavoYz

Joined: 07 Jul 2010 Posts: 894 Location: .ar
|
Posted: Mon 04 Mar 2013, 13:10 Post subject:
|
|
If I'm getting the idea, something like this shuold work:
Code: | if [ $( date | awk '{print $1}' )="sun" ]; then
cp $A $B && echo "Copied $A... OK"
else
# rest of the script
fi |
Shorter way:
Code: | [ $( date | awk '{print $1}' )="sun" ] && cp $A $B || ./script.sh |
|
Back to top
|
|
 |
divisionmd

Joined: 14 Jul 2007 Posts: 608
|
Posted: Tue 05 Mar 2013, 06:02 Post subject:
|
|
Hello GustavoYz,
Thanks!
What about this one: copy A to B on everyday except sunday?
thansk for help,
Best regards,
Johan
|
Back to top
|
|
 |
GustavoYz

Joined: 07 Jul 2010 Posts: 894 Location: .ar
|
Posted: Tue 05 Mar 2013, 10:06 Post subject:
|
|
Hi divisionmd,
Would be the same:
Code: | if [ $( date | awk '{print $1}' )="sun" ]; then
# something to do only in sundays
else
# the rest of the week:
cp $A $B && echo "Copied $A... OK"
fi |
|
Back to top
|
|
 |
Moose On The Loose

Joined: 24 Feb 2011 Posts: 835
|
Posted: Tue 05 Mar 2013, 11:15 Post subject:
|
|
GustavoYz wrote: | Hi divisionmd,
Would be the same:
Code: | if [ $( date | awk '{print $1}' )="sun" ]; then
# something to do only in sundays
else
# the rest of the week:
cp $A $B && echo "Copied $A... OK"
fi |
|
Beware of case. I get:
Tue Mar 5 07:13:27 PST 2013
The first letter is upper case.
To easily ignore case, use grep
Code: |
# if (date | grep -q -i "^tue" ) ; then echo "Works today"; fi
Works today
# if (date | grep -q -i "^wed" ) ; then echo "Works today"; fi
#
|
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 3450 Location: www.eussenheim.de/
|
Posted: Tue 05 Mar 2013, 11:47 Post subject:
|
|
date --help wrote: | Usage: date [OPTION]... [+FORMAT]
...
FORMAT controls the output. The only valid option for the second form
specifies Coordinated Universal Time. Interpreted sequences are:
...
%u day of week (1..7); 1 is Monday |
Code: | if [ $(date +%u) -eq 7 ] ; then echo copy_files; else echo no sunday ; fi |
Quote: | # if [ $(date +%u) -eq 7 ] ; then echo sunday; else echo no sunday ; fi
no sunday
# | Feel free to continue this test on next Sunday
|
Back to top
|
|
 |
GustavoYz

Joined: 07 Jul 2010 Posts: 894 Location: .ar
|
Posted: Tue 05 Mar 2013, 13:39 Post subject:
|
|
Yep, I use Spanish date format, so is all an aproximation.
But the idea is clear, no "cron-magic" is really needed, with date you're on.
|
Back to top
|
|
 |
|