sitekeeper
08-16-2001, 08:55 AM
I made a small bash script to backup to a sccond drive but everytime I try to run it I get "command not found".
I have the first line as:
#!/bin/bash
I can run the other lines of the script from the comand line but not the script. I chown the file to root, chmod the script to a+x.
Anyone have any ideas what I have wrong, I am fairly new at this! Learning from a book "Linux System Administration"
Thanks,
BOB:confused:
marco
08-16-2001, 10:01 AM
Try typing 'which bash' from the command prompt. It seems to me that bash is located somewhere else or /bin is not in the path.
Make sure you have specified the bash path correct (on my system it is in /usr/local/bin/bash)
If that doesn't work, try running the script with the following command: /path/to/bash script_name
Cheers, :)
sitekeeper
08-16-2001, 11:16 AM
Originally posted by marco
Try typing 'which bash' from the command prompt. It seems to me that bash is located somewhere else or /bin is not in the path.
Make sure you have specified the bash path correct (on my system it is in /usr/local/bin/bash)
I tried that and /bin/bash is the reply, strange!
It won't run using /usr/local/bin/bash/ either! :confused:
It is just 3 commands so I can just enter them at the command line. I just keep thinking it is something to do with ownership or permissions.
Thanks
BOB:D
marco
08-16-2001, 11:40 AM
Ok, I've got it: if the script is named "script_name" call "./script_name" instead of "script_name"
This tells the shell to look for "script_name" in the current directory, which isn't probably in the $PATH variable
Bye bye, :)
Gunzour
08-16-2001, 07:24 PM
macro may have figured it out.
If that doesn't work, it might be the commands within your script that are not in your PATH. It's likely that the PATH your interactive shell uses is different from the PATH used when you run a bash script.
The solution to that is to call any commands in your script by their full path. i.e., instead of saying something like:
tar cvf backup.tar /web/contents
try:
/usr/local/bin/tar cvf backup.tar /web/contents
(whether or not this is the cause of your current problem, it's always good practice to use full pathnames in all shell scripts!)
sitekeeper
08-17-2001, 05:23 PM
Ok, I've got it: if the script is named "script_name" call "./script_name" instead of "script_name"
The responce is:
[/scripts]# ./scripts
bash: ./scriptname: Not a directory
I have tried everything suggested and nothing works. I will keep trying, for now I will just use the command line to run the 3 lines in the script. That work fine, just slower.
Thanks for the help! :beer:
BOB:D
The Prohacker
08-17-2001, 05:32 PM
Try:
' bash ./scriptname '
sitekeeper
08-17-2001, 05:35 PM
I don't know why it would make a difference, but I chowned the script from root to nobody and now it runs. :)
Thanks again for all the suggestions! :beer: