Results 1 to 3 of 3
Hello: I am trying to write a script that cds into different directories to run a script (called code). I wrote the script (called script) in a directory with this ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-07-2012 #1
- Join Date
- Nov 2012
Simple Newbie-esque script using cd command
I am trying to write a script that cds into different directories to run a script (called code).
I wrote the script (called script) in a directory with this pathway (/projects):
... and so on and so forth, for several more.
I know this is very basic, and poor programming that could be condensed, but that is not my question. ohmy.gif)
For now, I just want to run this script so that I do not have to manually repeat the process directly into the terminal. If I were to type the lines in the script above (minus the header line of #!/bin/bash), each step should work. However, after the script called code is initiated in each directory, it takes about 15 minutes to complete (and produces several files).
However, after performing the command (chmod 666 script), followed by the simple command (script), all that happens is I get a message (Script started, output file is typescript) and then the typescript file says (Script started on Wed Nov 7 11:56:17 2012).
I believe the program then terminates because otherwise there should be files produced in each directory as a result of the code running there each time taking about 15 minutes as well.
Any advice on the source of the problem? Thank you in advance!
- 11-07-2012 #2
- Join Date
- Jun 2012
- SF Bay area
The permissions you selected, meaning 666, don't make your script executable. So when you typed "script", which I believe is what you called your shell script, the OS found an installed command named "script" and ran it. When I did a "man script" the documentation says "script makes a typescript of everything printed on your terminal", which explains the message you got.
So my suggested is to rename your bash script to something else to avoid confusion and change the permissions to "755". And in case you'd like to know why that works rather than just get a magic number to use, each digit in the permission is an indicator for a bitmap of "read", "write" and "execute" permissions. So to set "execute" permissions add 1, for "write" permissions add 2, and for "read" permissions add 4. That means "7" grants all three types of access and "5" means "read and execute".
The first digit applies to processes running with the UID of the files owner, the second applies to processes running with the GID of the file, and the last is for "anyone". So a permissions setting of "755" means the owner of the file can do anything, and everyone else can read it and execute it.
There are some other access levels folded into the permission, which is why you'll see 4 digit permissions settings like "1777", but that's not important for what you're talking about now. Check the man page for "chmod" for a more complete story on permissions settings.
- 11-12-2012 #3
- Join Date
- Nov 2012
It worked after your suggestions!
The only other thing I did not realize was that I also needed to run the absolute pathway from the current directory (i.e. I could not simply type the script name in the current directory as it would still interpret it as a command, I needed to type the entire absolute pathway with the script name at the end of that!)
Thanks for your help and explanation!!