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.
Related
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 1 year ago.
Improve this question
I am currently writing a bash script to automate my nodeJS deployment on my ubuntu test server. The port is listed within a the bin/www file. In the example line below the port is 3003 that I need to get in a variable of my script:
var port = normalizePort(process.env.PORT || '3003');
Do I need to parse the file with some regex in order to get the port number in a variable to work with it?
If you want to parse that 3003 out in a bash script you'll need to get the line in question, then pipe it to something that can get the value out. Something like:
grep 'normalizePort' <file_with_the_port> | grep -oE '[0-9]+'
You'll need to play around with it to get you to where it works for you.
However, as others have pointed out, that won't give you the port. That will only give you the default port. The real port is in an environment variable (that's what process.env means in this case), thus in a bash script you'd probably be able to access that PORT variable like so:
APP_PORT=${PORT:-3003}
You ought to read more on environment variables. Ideally you shouldn't be parsing ports out of files, unless those files are specifically created for storing config in a machine-friendly format like YAML or JSON.
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 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"
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 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