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) --
I created a small list of commands and put the commands into a text file
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.
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:
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.