I have a bash script which backups my source code on a 10 minute basis thru crontab. Script was working until the end of August. It’s not working since September 1st. This is the script:
#!/bin/sh
date=`date +%e-%m-%y`
cd /home/neky/python
tar -zcf lex.tar.gz lex/
echo $date
mv lex.tar.gz lex-$date.tar.gz
mv lex-$date.tar.gz /home/neky/Dropbox/lex/lex-$date.tar.gz
If I execute it manually, it print the current date 4-09-12, and this error mv: target ‘4-09-12.tar.gz’ is not a directory
What could be the problem?
Your
datecontains a space when the day of month is a single digit (which also explains why it only stopped working in the new month). That results in your command being split up, i.e.Use
date +%d-%m-%yinstead which will give you04-09-12(note%dinstead of%e).If you really want a space in the name, you’ll need to quote your variables, i.e.: