Jump to content

Linux Question


Sasun

Recommended Posts

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.

Link to comment
Share on other sites

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/sh

or

#!/bin/bash

 

in the beginning of the file to make the script run under a specific shell for deterministic behavior.

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

it would help to see the contents of your script. First thing to check is whether sh or bash are actually in /bin

Checked, 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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...