Sasun Posted November 19, 2003 Report Share Posted November 19, 2003 Here is a question: I want to execute a series of commands on a linux from batch. I want to put them in one file and execute the file like a command. What should I do? Should it be a shell script? (I know shell script on unix, but not sure if it exists on linux and if it's the same)This probably doesn't matter for the solution, but just in case: my goal is to log on on a mysql database and execute a few sql commands. I can do all these one by one from the prompt, but I want to do all of them at the same time with one command. Any help would be appreciated (I am too lazy to go to books and such... ) P.S. sorry had to move this from apache thread, apparently no connection. Quote Link to comment Share on other sites More sharing options...
Sip Posted November 19, 2003 Report Share Posted November 19, 2003 it depends on which shell you are using but usually it's as simple as writing all those commands in a text file and enabling execution permission on that file. People also usually put something like #!/bin/shor#!/bin/bash in the beginning of the file to make the script run under a specific shell for deterministic behavior. Quote Link to comment Share on other sites More sharing options...
Sasun Posted November 19, 2003 Author Report Share Posted November 19, 2003 Sip jan, thanks. I moved the post to a new thread because of no connection to this topic. I tried what you are suggesting except the "#..." parts. I will try with them also, but I don't know which one should be used with my system. Quote Link to comment Share on other sites More sharing options...
Sasun Posted November 19, 2003 Author Report Share Posted November 19, 2003 Tried both versions, they both give the same error: bash: sql.txt: command not foundThis also means I have the bash version. P.S. I somehow managed to move around the posts Quote Link to comment Share on other sites More sharing options...
Sip Posted November 19, 2003 Report Share Posted November 19, 2003 muahs koo sasun I would stick with either sh or bash. Just use #!/bin/sh and you should be good to go. I am guessing you are not using anything that is very shell specific and just basic comands. Quote Link to comment Share on other sites More sharing options...
Sip Posted November 19, 2003 Report Share Posted November 19, 2003 it would help to see the contents of your script. First thing to check is whether sh or bash are actually in /bin Quote Link to comment Share on other sites More sharing options...
Sasun Posted November 19, 2003 Author Report Share Posted November 19, 2003 it would help to see the contents of your script. First thing to check is whether sh or bash are actually in /binChecked, sh is there, bash is symbolically linked to sh. Here is my test code:#!/bin/sh mysql -u(username) -p(password) Thats all for the initial test. Quote Link to comment Share on other sites More sharing options...
Sip Posted November 19, 2003 Report Share Posted November 19, 2003 It should work. Is mysql in the path? You have set the correct permission chmod 755 on the script file? I would replace the mysql command with "ls" or something to see if you can get anything to work. Quote Link to comment Share on other sites More sharing options...
Sasun Posted November 19, 2003 Author Report Share Posted November 19, 2003 This doesn't work permissions are 777 #!/bin/bash ls Quote Link to comment Share on other sites More sharing options...
Sip Posted November 19, 2003 Report Share Posted November 19, 2003 HAHAHAAHA!!! I think I know your problem. Your current directory may not be in your command path. If your script file is sql.txt, run it like: ./sql.txt Quote Link to comment Share on other sites More sharing options...
Sasun Posted November 19, 2003 Author Report Share Posted November 19, 2003 WOW!!!! Amazing, it works now. I never had such a problem. By the way, how did you know that it's sql.txt? that's exactly what I have. Thanks a lot Sip, and lots of muahzzzz Quote Link to comment Share on other sites More sharing options...
Sip Posted November 19, 2003 Report Share Posted November 19, 2003 I thought about what could be causing your error (you posted above). Then realized where "sql.txt" comes in!!!! Quote Link to comment Share on other sites More sharing options...
Sasun Posted November 19, 2003 Author Report Share Posted November 19, 2003 oh.. well i gave you the error message and forgot about it... damn it, i am getting old... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.