How to get shell commands working through ruby?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get shell commands working through ruby?
# 1  
Old 07-25-2008
How to get shell commands working through ruby?

Hi all,

I am a newbie currently trying to execute shell commands from ruby instead of a shell script.(This method is conceived only for solaris so no issues with porting to other OS and all)
Eg:
Consider the command 'ls"
with a shell script ,I would use it like this
bash# ls
<all the contents in that dir would be displayed>

Now how do i get to do the same with ruby?

I dont want to use methods like recursively searching the directory and then displaying the contents(through some while loop )
It has to be only "ls", as in i need to make "ls" work on solaris through ruby as it would if it were to be written In a shell script?

Thanks
# 2  
Old 07-25-2008
You can get the listing with ruby, why you want to use ls?

Code:
ruby -e'puts Dir["*"]'


Anyway ...

Code:
ruby -e'puts `ls`'

# 3  
Old 07-25-2008
Actually ls was just an easy example that i mentioned.
I am actually improvising a few commands through ruby and since am a beginner i have very little idea of programming in ruby.
So just wanted to have an idea.
By the way can you guide me to any good tutorials for beginners

Thanks
# 4  
Old 07-25-2008
Well,
I'm quite new to ruby too, but it's the next language in my personal list (after Perl). All I have for now is Practical Ruby for System Administration (available on Amazon). You can also check the resources listed at hypermetrics.com/rubyhacker/clrFAQ.html#tag12 .
# 5  
Old 10-05-2008
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Tilde commands not working

Hi I have a script that it sends emails to various recipients using mailx, but some of the recipients should be sent as BCC, but ~b flag when used in the following line, does not put the gmail address as BCC: echo "node $output is down" | mailx -s "$output not pinging" sadf@xyz.com ~b... (8 Replies)
Discussion started by: fretagi
8 Replies

2. Shell Programming and Scripting

Converting shell/awk to ruby

any idea on how to get started with this: shell script: awk '/{/,/}/' ~/newservices.txt | while read line do BEGIN=$(echo "${line}" | egrep ":" | egrep "{") if ; then checkname=$(echo $line | awk -F":" '{print $1}' | sed 's_"__g') echo "{"... (1 Reply)
Discussion started by: SkySmart
1 Replies

3. Shell Programming and Scripting

Sftp commands not working in shell script

hi, i am having 2 linux boxes as source and 1 linux box as destination.i want to create a shell script containing code to transfer a csv file from either of the 2 linux boxes (file will be present in just one box, i need to check both the boxes to see which box has the csv file) to 3rd linux box... (1 Reply)
Discussion started by: linuxlearn2013
1 Replies

4. Shell Programming and Scripting

Commands not working in script file

Hi All, I have created a shell script having some general copying and moving commands. Commands are working fine in Shell but while executing the shell script it is showing an error mv: cannot stat `/apps/orarpt/in/*': No such file or directory command is mv $IN_DIR* $ARCHIVE_DIR where... (5 Replies)
Discussion started by: maindola.amit
5 Replies

5. Shell Programming and Scripting

Parameters passed to commands but not working in Bash shell

Hi, I am trying to do this thing useing my shell bash ( sorry for my english ) I have in a file 63 hostnames, i wanna ask to the DHCP admin, to reserv that reserves 63 IP addresses of this hosts, using their mac address. I have thinked this script: for ((i=1;i<63;i++)); do arp $(head... (10 Replies)
Discussion started by: Cypress
10 Replies

6. Fedora

wall and write commands are not working

hi friends i am using fedora linux operating system on the server and two clients(with windows os) are connected to it(server ).but here wall and write cmds are not working to send messages from one system to another system . pls help me (4 Replies)
Discussion started by: sankar_vitam
4 Replies

7. Shell Programming and Scripting

Can BASH execute commands on a remote server when the commands are embedded in shell

I want to log into a remote server transfer over a new config and then backup the existing config, replace with the new config. I am not sure if I can do this with BASH scripting. I have set up password less login by adding my public key to authorized_keys file, it works. I am a little... (1 Reply)
Discussion started by: bash_in_my_head
1 Replies

8. UNIX for Advanced & Expert Users

commands after .profile modification not working

Hi , I have modified .profile and after that i ran it as .profile. Now no command i working even ls is not working When i type ls , it is showing that -ksh not found I tried to run as . $home/.profile , it is saying as permission denied . How can we do that .. any idea.. Thanks... (2 Replies)
Discussion started by: arunkumar_mca
2 Replies

9. Shell Programming and Scripting

pwd & cd commands not working in shell script

Here is my script #!/bin/bash pwd cd /var/lib/pgsql Both "pwd" and "cd" are not executed is there any other way i can change the current working directory to /var/lib/pgsql pls help! (9 Replies)
Discussion started by: perk_bud
9 Replies

10. UNIX for Dummies Questions & Answers

differnce between working of at and crontab commands

h I would like to know the differnce (both working and how) between at command and crontab.. Thanks in advance Satish D (2 Replies)
Discussion started by: doddas
2 Replies
Login or Register to Ask a Question