Problem Running Touch From Script

Hi

I'm trying to touch a number of files. I thought that it would be time-saving to put all the touch commands into a script and execute the script from the command line.

This is what I did (as a test) --

  1. I created a small list of commands and put the commands into a text file
  2. I set the chmod for the files that I want to touch to 777 and the chmod for the bash script to 755

I know that each individual command in the script is OK because if I copy and paste them directly into the command line they run fine and the timestamps of the files are changes.

However, when I run the script, it seems to run OK (ie there are no error messages) but the files remain unchanged.

Here's the content of my test script:
touch -c -t 200402032227.47 "./var/www/vhosts/mydomain.com/mydir/testFolder/test.txt"
touch -c -t 200302032227.47 "./var/www/vhosts/mydomain.com/mydir/testFolder/test2.txt"

If anyone can see / point the way to where I'm going wrong that would be really great.

Thanks for your attention.

Viola

I dont see any issues here,esp when you say that the same commands when cut and pasted onto the terminal yield the result...
(Am no expert either!!)

However you could try this to figure out the error you have (if any )in the script...

bash -xv <your script>
This should be a good starting point....

Secondly you could try this...
/usr/bin/touch <your file name>
and see if it works!!!!

would like to know what happens,keep me posted!!!

If you want to save time, you can break up the touch and chmod commands instead of using a one-liner

Thanks for your reply.

I tried both your suggestions.

The first produced this output:

[root@ip-111-222-333-444 mydir]# bash -xv commands.bash
touch -c -t 200402032227.47 "./var/www/vhosts/mydomain.com/mydir/testFolder/test.txt"
+ touch -c -t 200402032227.47 ./var/www/vhosts/mydomain.com/mydir/testFolder/test.txt
touch -c -t 200302032227.47 "./var/www/vhosts/mydomain.com/mydir/testFolder/test2.txt"
+ touch -c -t 200302032227.47 ./var/www/vhosts/mydomain.com/mydir/testFolder/test2.txt

I'm not really sure how to interpret what this means, though.

The other suggestion produced an error "bash: /usr/bin/touch: No such file or directory". I probably misunderstood what you were describing that I should do in my suggestion, though. This was the command I typed:

[root@ip-111-222-333-444 /]# /usr/bin/touch ./var/www/vhosts/mydomain.com/mydir/commands.bash

Thanks for your suggestions so far. Any more advice would be very much appreciated.

Viola

incredible -- sorry, but I'm not sure what you mean. Please can you elaborate?

First check where really a home of thouch commanda is:

</> whereis touch
touch: /usr/bin/touch

Then type the whole path of the touch command (what you get, of course) to your file commands.bash.
That's all I can say. Script works ok on my aix.

Thanks for your help. I now have it working.

The path to my touch was ok. It turned out that your first suggestion worked helped me fix it, but I didn't realize because I'd introduced another error in the fix.

The problem was a carriage return (\r) at the end of each command line. I fixed this and created a new commands.bash script. It still didn't work, so I thought, "Darn, it still doesn't work" so I posted where I'd got to so far and went to bed. This morning I suddenly realized that by changing the commands.bash file, I also had to set it's chmod back to 755. I did this, and it worked.

Thanks a lot for your help. It was the suggestion to run the script verbose that really helped. This was my first ever shell script and I was "feeling around in the dark" a bit. Using the verbose option is a debugging technique that I can remember in the future.

Viola