Run many commands in Linux Mint quickly - linux

I'm very much learning my way around the command line. I have several commands I want to occasionally run, mostly on a restart, but at other misc times as well. Can I have some kind of file which can contain these commands and execute the file from the command line so that they are all ran at once? Would this be the general correct approach? And if so, how would I actually achieve this? Thanks for your guidance.

What you want is an "init script".
http://www.tldp.org/HOWTO/HighQuality-Apps-HOWTO/boot.html

This enables you to define the behaviour of several services, and then determine in what run level you want them to start / stop at (EG: run level 6 for restart).
http://www.tldp.org/LDP/sag/html/run-levels-intro.html

You might also benefit from some "alias"'es in your shell (assuming you are using BASH).
http://tldp.org/LDP/abs/html/aliases.html

Related

How to create a script that opens multiple terminals and runs different programs on them?

Good day everyone,
I am working on a project that requires me to have 7+ programs (no GUI, runs on shell) open, all interacting with each other. For example, Program 1 asks a question to Program 2, and it uses Program 3 and 4 to solve that etc.
So what I do is, I open many terminals and run each one on a different terminal, then I place them on my screen and go ahead. But this is a troublesome process, as every time I need to recompile I need to run them all one by one again, even worse, if I ever turn my computer off, I need to open many shells, go to the directories, run them all so and so.
What I want is a file that would open the necessary terminal windows for me and go to the correct directory on each, then run the programs. I don't know much about shell-scripts, but I assumed this must have been possible. Can you give me any directions? Note that the programs should not run in background or in different tabs. I need to be constantly observing the displays.
I have read this post about a similar issue but that does not work for me, because I need them on different terminals.
Thank you.
We suppose you are using gnome terminale, so the command would be:
gnome-terminal --working-directory "{{APP_FOLDER}}" --command "{{APP_EXCUTABLE}}"
That approach can be traslated to any other terminal emulator.

Why isn't this command running properly?

So I'm making a better command-line frontend for APT and I'm putting on some finishing touches and when the code below runs.
Command::new("unbuffer")
.arg("apt")
.arg("list")
.arg("|")
.arg("less")
.arg("-r")
.status()
.expect("Something went wrong.");
it spits out:
E: Command line option 'r' [from -r] is not understood in combination with the other options.
but when I just run unbuffer apt list | less -r manually in my terminal it works perfectly. How do I get it to run properly when calling it in Rust?
Spawning a process via Command uses the system's native functionality to create a process. This is a low level feature and has little to do with your shell/terminal that you are used to. In particular, your shell (e.g. bash or zsh, running inside of your terminal) offers a lot more features. For example, piping via | is such a feature. Command does not support these features as the low level system's API doesn't.
Luckily, the low level interface offers other means of achieving a lot of stuff. Piping for example is mostly just redirecting the standard inputs and outputs. You can do that with Command::{stdin, stdout, sterr}. Please see this part of the documentation for more information.
There are a few very similar questions, which are not similar enough to warrent closing this as a dupe though:
Execute a shell command
Why does the compgen command work in the Linux terminal but not with process::Command?: mentions shell built-in commands that do not work with Command.
Executing find using std::process::Command on cygwin does not work

where to look for previously executed commands

I want to understand how up/down arrow keys help to navigate through previously executed commands. which memory it access to get last executed command?
Currently i am working on unix similar Machine "Stratus VOS" where i can see only last 1 executed command and that too with F10 key.
I want to create a script/tool which can help to me to get at least last 10-15 executed commands to save my time during development work.
what i noticed so far on Stratus Machine:
1: fc command doesn't work.
2. no HISTFILE is maintained. no history command works.
what i thought to implement:
find which memory in system holds last executed command, access that memory(whenever Enter key is pressed ) and keep writing in file.
am i on right track? is there any better solution for this?
I would suggest that while possible your solution is possibly overcomplex and likely to be difficult and possibly unreliable. I would instead consider using the Stratus VOS GNU tools package which includes a full GNU Bash shell with all the features you expect including the command history support.
A little documentation on GNU tools for Stratus VOS appears to be available here though I would suggest contacting your vendor for more information or support.

Linux equivalent of Windows "Startup" folder

I want to run a program when my embedded Linux's desktop has started up, in the same way as Windows runs programs in the "Startup" folder. How can I do this?
Specifically, my target hardware is Beaglebone Black, the Debian variant (rev C board). The Window Manager is the default one.
In Linux these are called init scripts and usually sit in /etc/init.d. How they should be defined varies between different distros but today many use the Linux Standard Base (LSB) Init Script format.
Good readings on this:
https://wiki.debian.org/LSBInitScripts
https://www.debian-administration.org/article/28/Making_scripts_run_at_boot_time_with_Debian
There are multiple ways to start a program, it turns out. LXDE - the window manager - supports auto-start of .desktop files places in either ~/.config/autostart or /etc/xdg/autostart - hooray!
http://wiki.lxde.org/en/Autostart
Except... though I can run a simple program as proof-of-concept in this way, when I try to run mine, it fails. I can't figure out why. The file
.xsession-errors.old
contains X server errors ("resource temporarily unavailable").
I am now using another mechanism - running the code from a shell script (this is necessary because I need to specify a working directory for the program). This uses the "autostart" file in /etc/xdg/lxsession/, and at least it works. Well kind of. I either have to "sleep 5" before running, or prefixing the run with an # symbol which forces a retry if it fails. It looks a little like something my code is dependent on is not in place at the precise time the autostart mechanism finds it. I can find no way of ensuring startup order. This is plainly a crock of stinky stuff.

Is there a good way to submit jobs to a cluster using bash?

Is there a good tool out there to do this on a Linux machine using the bash shell? All I need is to issue different commands on a set of nodes in a cluster and when one of them is done with the job, I'd like to submit another one. Something very similar to what Hadoop can do. I would be interested in knowing the status of the job as well but even otherwise is fine. Any suggestions?
Programs like Sun Grid Engine and Mosix will let you submit all of your jobs at once and will automatically load balance them (meaning it will queue them up so that only the right number are running on a given node at a time).
I've had good experiences with these in scientific computing (on Linux with bash) and highly recommend either.
There's also parbash (Parallel Bash):
http://code.google.com/p/parbash/
You could also use mounted NFS/SMB partition and write some scripts yourself.

Resources