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
Looking for a script that copies files only on Sundays
- divisionmd
- Posts: 606
- Joined: Sat 14 Jul 2007, 20:42
If I'm getting the idea, something like this shuold work:
Shorter way:
Code: Select all
if [ $( date | awk '{print $1}' )="sun" ]; then
cp $A $B && echo "Copied $A... OK"
else
# rest of the script
fi
Code: Select all
[ $( date | awk '{print $1}' )="sun" ] && cp $A $B || ./script.sh
- divisionmd
- Posts: 606
- Joined: Sat 14 Jul 2007, 20:42
Hi divisionmd,
Would be the same:
Would be the same:
Code: Select all
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
- Moose On The Loose
- Posts: 965
- Joined: Thu 24 Feb 2011, 14:54
GustavoYz wrote:Hi divisionmd,
Would be the same:Code: Select all
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: Select all
# if (date | grep -q -i "^tue" ) ; then echo "Works today"; fi
Works today
# if (date | grep -q -i "^wed" ) ; then echo "Works today"; fi
#
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
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: Select all
if [ $(date +%u) -eq 7 ] ; then echo copy_files; else echo no sunday ; fi
Feel free to continue this test on next Sunday# if [ $(date +%u) -eq 7 ] ; then echo sunday; else echo no sunday ; fi
no sunday
#