Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to add a cron job that scp a folder to a server with on the server the folder name is in another folder whose folder name is a timestamp like ddmmyy

something like

scp -r <foldername> user@server:path/to/destination/ddmmyyhhmmss

ddmmyyhhmmss: date month year hour min sec

share|improve this question
    
And what is the problem? Of course your 'path/to/destination' must exist. –  Jiri Xichtkniha Feb 8 '13 at 13:49
add comment

1 Answer

up vote 2 down vote accepted

You can get the date via the date command which lets you specify a date format via %d, %m, etc. Cron treats % characters as special so you need to escape them. Something like this should copy your file at the top of every hour.

0   *   *   *   *   scp -r <foldername> user@server:path/to/destination/$(date +\%d\%m\%y\%H\%M\%S)
share|improve this answer
    
Thank you, it works –  Noor Feb 8 '13 at 14:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.