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.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I have a shell script written like so:
#!/bin/bash
cd Documents/Hi_tech_team_10/
chmod +x /Users/twoodwa/Documents/Hi_tech_team_10/test.rb
ruby test.rb
when i execute it in the terminal it works perfectly, but when i set it as a cron job by doing
crontab -e
then editing and saving the file with
*/10 * * * * /Users/twoodwa/Documents/Hi_tech_team_10/test.sh
the script either doesn't execute, or it is doing something different than just running it like it does from the terminal.
what is the issue?
EDIT: i have changed the script to use absolute paths as so, still not working :
#!/bin/bash
chmod +x /Users/twoodwa/Documents/Hi_tech_team_10/test.rb
ruby /Users/twoodwa/Documents/Hi_tech_team_10/test.rb
First checkpoint: if script is executable
Second checkpoint: you should use absolute paths
Third checkpoint: never trust environment. Cron has it's own environment (true, suggested in comments)
Good idea: Addding some logging to a terminal/file to check execution and when it had failed.
The issue is in crontab, change crontab to pointing to test.rb
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 does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I am working on a Mac. I am trying to use the fork command to run another sh file on Terminal.app:
$ fork sh
bash: fork: command not found
What's wrong with my command?
fork isn't a shell function.
You can run an executable script directly /path/to/script.
You can source/. a script to run it in the current shell . path/to/script.
You can also run the shell directly on the script bash /path/to/script.
To run a command in the background, you can put an ampersand (&) on the end.
So for example, if your command is /path/to/some/program some args here, you could run it in the background (and continue entering commands in your foreground shell) using:
/path/to/some/program some args here &
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
This should be surprisingly simple, but it eludes me. I'm trying to set up a simple command such that I can type: ruby myfile someparams and it will return something via stdio.
I want to include a gem, like https://rubygems.org/gems/github-linguist and pass something to it and see what it has as a response.
I'm a bit lost. Ideas?
Here's a sample script that just echoes its arguments:
#!/usr/bin/env ruby
puts "The arguments were:"
ARGV.each { |curr_arg| puts curr_arg }
Save this to foo.rb, then chmod a+x foo.rb. You can either move it to some location on your PATH, in which case you can just type foo.rb some args from anywhere, or you can run it explicitly from the current directory with either ./foo.rb some args or ruby foo.rb some args.
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.