Question : bash script error using date and %k

Hi

I have a back up script that runs every hour,  in the script I used the date function to create a suffix for the archive created for the backup

suffix=$(date +%y%m%d.h%k%M)

The script originally only ran daily and was

suffix=$(date +%y%m%d)

The originally script worked correctly 100% of the time,  Now the strainge part,  the new script with the   time element only works from 1000 to 2359

for some reason during the hours 00.00 to 0959 the script fails:


/home/user/public_html/site.com/backup/sqlhourly.sh: line 5: mysql/db.$suffix.sql: ambiguous redirect
tar: 930.tgz: Cannot stat: No such file or directory
tar: mysql/*: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors

Has anybody come across the same problem using the %k date element a script..  

Thanks

Answer : bash script error using date and %k

Hi,

%k means

Display the 24-hour-clock hour clock as a right-justified, space-filled number ( 0 to 23).

So, when the hour is between 0 and 9 you will have a space in your filename.

Better use %H

wmp

Random Solutions  
 
programming4us programming4us