Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I created the file test.sh which contains ls -ltr & jobs command. When I run it, it gives me the output of ls -ltr, but for jobs command it doesn't give me anything, not even an error.4
Whats wrong?
jobs is an interactive command -- it is not meant to be used from scripts, and doesn't do anything useful in a script (but it could plausibly do something useful in a shell function called from an interactive session; so disabling it in code isn't really appropriate, either).
To keep track of background jobs, collect their PID:s when you start them.
ls -ltr &
pid=$!
printf 'pid: %s' "$pid"
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have 3 parts for my workflow that I would like to alias to a single line ‘workflow’. Each command will run a server in terminal so I’ll need the command to open multiple tabs preferably on the same window.
I don’t know too much about writing bashrc scripts so I’m not sure how to put it into a single line. Essentially I want gnome-terminal —-tab —-tab —-tab to run and then for each tab run one of these; psql mydb, Jupyter lab, metabase.
Any help would be great!
You can try:
gnome-terminal --tab -e "psql mydb" --tab -e "Jupyter lab" --tab -e "metabase"
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to make a bash script that will ls the catalog and if it finds file test it will launch mplayer, is it possible?
If I understand your requirement correctly, one option would be to use find:
find /path/to/catalog -type f -exec mplayer {} +
This searches the catalog directory for any files and builds a command using the results (for example if file1 and file2 were found, the command executed would be mplayer file1 file2). If no files are found, no command will be executed.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I wont write some script in Ruby on Linux server. I need statistic from server and I'm a beginner in Ruby.
I have problem with Linux commands, because if I use exec to use Linux command, my program is fallen without error.
disks = ["sda", "sdb"]
Code:
disks.each do |disk|
puts "disk test start"
exec "smartctl -a /dev/#{disk} > /tmp/sestavy/#{disk}"
puts "disk test end"
end
Output:
[root#banan sestavy]# ruby test.rb
disk test start
[root#banan sestavy]#
Thanks
Honza
That's just what exec does: it replaces the currently running program with a new one. This is not specific to Ruby, it works the same way in the shell, in C, in pretty much any other environment.
When you use exec, it replaces the current process with what you want to execute. So it won't return to your Ruby script. See this explanation for different methods for shell execution.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm working a shell script to admin out email system. Essentially I get the users info and grep it to get the data I need. I've ran the below commands in terminal and they work as intended but when I use the below script I get an error "Command not found". I think its trying to run the 3rd line as a command. Anyone know what could be the problem here?
read -p "Enter email address to remove from groups: " purge_email
purge=$(python /gam/gam.py info user $purge_email)
purge_chunk=$($purge | grep -A 100 "Groups:")
echo $purge_chunk
Try:
purge_chunk=$("$purge" | grep -A 100 Groups:)
the $purge should be evaluated as formatted output the way gam kicks it out in a txt file or .csv you would use as a data source for a gam script in bash.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I wrote the following script:
#!/bin/bash
./vlc $nom > $fichier
gedit $fichier
In the execution of my script. The first command (. / vlc $ name> $ file) runs but once the video is playing. The second command is not executed.
For that the second command runs, I would have to return to the console and I do: Ctrl+C
I would like everything is done automatically.
You have any idea please?
Maybe what you want is for the first program to run in the background:
./vlc $nom > $fichier &
gedit $fichier