What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Runnings several commands

DrTeeth

Senior Member
When running several commands, is it possible to run them together like in a batch file or must they be run one after another?

Using SSH client (Xshell 4) to connect to my N66U running Merlin's 374.42

Thanks
 
I'm not sure what you mean by "like a batch file" because batch files, like scripts, execute commands sequentially. But if you've got a command that takes a long time to run and you don't want to wait for it to finish (and return the command prompt) you can run it in background.

To run a command in background just put an ampersand at the end.
Code:
# sleep 5 &
Or do you actually want to create a shell script (like a DOS batch file)? https://github.com/RMerl/asuswrt-merlin/wiki/User-scripts#creating-scripts
 
Last edited:
When running several commands, is it possible to run them together like in a batch file or must they be run one after another?

Using SSH client (Xshell 4) to connect to my N66U running Merlin's 374.42

Thanks

Depends what you want to do.

If you want to run three commands with no direct relation to one another, separate them with semi-columns:

Code:
mkdir /tmp/test ; cp /mnt/sda1/myfile /tmp/test ; ls /tmp/test

If you want to run the second command only if the first one succeeded, use &&. For example, this is how I upgrade my router when flashing a test build:

Code:
mtd-write2 /tmp/l.trx linux && reboot

If the first command fails, the reboot won't occur. That gives me a chance to re-flash a proper FW.

And there are the piping capabilities of Linux, where the output of one command can be provided to another command. For example, this will display your nvram, sorted in alphabetical order, pausing between every pages:

Code:
nvram show | sort | more
 
I was thinking of the commands used for changing locales. Rather then running each line one at a time, I could paste the whole lot to run. Sounds like your first example would do what I want.

Thanks.
 

Similar threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Back
Top