Problem Running Touch From Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem Running Touch From Script
# 1  
Old 05-23-2008
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
# 2  
Old 05-23-2008
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!!!
# 3  
Old 05-24-2008
If you want to save time, you can break up the touch and chmod commands instead of using a one-liner
# 4  
Old 05-24-2008
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
# 5  
Old 05-24-2008
Quote:
Originally Posted by incredible
If you want to save time, you can break up the touch and chmod commands instead of using a one-liner
incredible -- sorry, but I'm not sure what you mean. Please can you elaborate?
# 6  
Old 05-24-2008
First check where really a home of thouch commanda is:
Code:
</> 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.
# 7  
Old 05-24-2008
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Script problem when running on crontab

Hi guys! I created a backup script that works fine when I run manually, but when I put a crontab job to execute it the result are not the expected. (not a time problem). Here is my script: bash-3.00# cat /bk_tool/backup2.sh #!/usr/bin/csh clear set DIR_HOST='SCP08' ... (3 Replies)
Discussion started by: andredemartini
3 Replies

2. Shell Programming and Scripting

Problem on running a script

Hi all, Running follow command on terminal; $ glance -T cloudlive -I ubuntu -K ubuntu123 -N \ http://127.0.0.1:5000/v2.0/OpenX add name="cirros" is_public=true \ container_format=ovf disk_format=raw < \ /srv/cirros-0.3.0-x86_64-disk.img It works without problem. Putting it on a... (5 Replies)
Discussion started by: satimis
5 Replies

3. Shell Programming and Scripting

Problem running a program/script in the background from a script

Hi all, I have a script that calls another program/script, xxx, to run in the background. Supposedly this program at most should finish within five (5) minutes so after five (5) minutes, I run some other steps to run the script into completion. My problem is sometimes the program takes... (5 Replies)
Discussion started by: newbie_01
5 Replies

4. Shell Programming and Scripting

Problem with crontab running a script

I am trying to use the CRON utility in Fedora 11 & CentOS... I intend to run a script which pops up a warning message every hour and i made the following entry using "CRONTAB -e " * * * * * sh /bin/myscript.sh But this does not seem to be running. Another thing to note is that,... (4 Replies)
Discussion started by: Vabiosis
4 Replies

5. Shell Programming and Scripting

Problem in running a shell script

Hi, I'm trying to run a simple shell script whose contents are pasted below. #!/usr/bin/ksh echo $PATH performbuild { echo "Inside performBuild function" } echo "Main Shell started" performbuild echo "Main Shell ended" DV> ls -ltr total 48 -rwxr-xr-x 1 pb5377 it-ibm ... (5 Replies)
Discussion started by: blp_18
5 Replies

6. Shell Programming and Scripting

K script not running / syntax problem

Hi, I have following K script, that is in rc0.d directory to be run on shutdown. It's linked using the 'ln' command to init.d.Can anyone tell me as to why it's not running, or if i have incorrect syntax?I get: "test: argument expected type=uname -p + " When running it with sh -x ... (8 Replies)
Discussion started by: darrlaw
8 Replies

7. Shell Programming and Scripting

Problem with running the remote script

Hi All, I am running a script which is present on remote machine using ssh command. the remote script is failing when try to load a property file. It says file does not exist. Any idea what should be the problem for this. Thanks Supriya. (7 Replies)
Discussion started by: supriyabv
7 Replies

8. UNIX for Dummies Questions & Answers

problem running script

hey, i'm trying to run several processes due 2 loops : the code is: cd ${TIBCO_HOME}/tra/domain/${DOMAIN}/application/ for app_name in ls * do echo $app_name if && && ; then exit else echo $app_name cd $app_name pwd for ps_name in ls *.sh do echo... (2 Replies)
Discussion started by: ohadr
2 Replies

9. Shell Programming and Scripting

Problem in Running Script

Hi friends, i have written one small script named as "size.sh"..... while running its giving syntax error at line no 2: 'str=$' unexpected. How to run this file ??? please help me. file content is : ----------------------------- #!/bin/sh str=$( df -k | grep /usr/local)... (14 Replies)
Discussion started by: samfrance
14 Replies

10. Solaris

Problem running script remotelly.

Hi, i would like a help with this problem. i have the following situation: 4 workstations SUNs: SunOS porsche 5.8 Generic_117350-18 sun4u sparc SUNW,Sun-Blade-100 SunOS jaguar 5.8 Generic_108528-18 sun4u sparc SUNW,Sun-Blade-100 SunOS mercedes 5.8 Generic_117350-18 sun4u sparc... (2 Replies)
Discussion started by: dougpss
2 Replies
Login or Register to Ask a Question