I have the following problem. I have a bash script that uses wget to get a few files from the build server, and then scp's them over to the production system: Here is the relevant snippet:

#Several of these lines
wget -nv -O birt_reports.zip "http://buildserver:8111/guestAuth/repository/download/bt6/.lastFinished/birt_reports.zip"

#files in the for loop left out for simplicity
for upload_file in "birt_reports.zip"; do

    scp -B -i /root/$keyfile  $upload_file $user@gateway:/home/$user/deploy_staging
    touch $upload_file

Even with the touch in there the time shown in ls -l of the directory is the time the file was first created. If I do the wget outside the bash script or the touch outside the bash script, the time updates correctly.

What could the issue be?

  • I assume the account has write permissions on the file.. – Grizly Sep 3 '10 at 5:28
  • Yes, it is run as root. – Yishai Sep 7 '10 at 18:34

Using the bellow command it is supose to set the timestamp of the file to your system current datetime:

touch -t `date +%y%m%d%H%M.%S` /path/to/filename

You could try it instead of the plain touch command alone.

Also when you run your bash script run with:

bash -xv your_bash_script.bash

also try using the full path of your commands, to verify the full path of the command do:

whereis touch

Since you could be using this without a shell enviroment using the full path is more recommended to make sure it will run every command without problems.


perhaps /bin/touch -m $upload_file is better suited, as it changes the modification time to the current time.


Is the file being properly scp'ed? (I can't comment on your question post)

If not, then I think you're missing something to the uploaded file path within the for loop for both commands. Prix points out the way to check the actual commands.

  • Yes, oddly the file does correctly copy. – Yishai Sep 7 '10 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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