[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Run command after Prompting from User...

Usman Akram

7/21/2008 10:01:00 AM

Hi,

i am new in Ruby, and i got a problem, that is when i run the system
command..


i want to add users to the Linux OS, so for that i have to prompt
the username from the user, and i store that username in a variable,

Now please tell me that how can i use that variable in the system()
function of Ruby...

i do this but not working :-(

user_name = gets

system ('adduser -m $user_name')

so please any body tell me that how can i run the system command, by
using variable in the system() function....?????

from
Name: Lucky
Email: ajaonchat@yahoo.com
--
Posted via http://www.ruby-....

4 Answers

Tim Hunter

7/21/2008 4:47:00 PM

0

Usman Akram wrote:
> i do this but not working :-(
>
> user_name = gets
>
> system ('adduser -m $user_name')
>
> so please any body tell me that how can i run the system command, by
> using variable in the system() function....?????

U:>irb
irb(main):001:0> user_name = "timothy"
=> "timothy"
irb(main):002:0> puts "user_name is #{user_name}"
user_name is timothy


See "Strings" here:
http://ruby-doc.org/docs/ProgrammingRuby/html/tut_std...
--
Posted via http://www.ruby-....

Sandor Szücs

7/21/2008 4:53:00 PM

0

On 21.07.2008, at 12:00, Usman Akram wrote:

> i do this but not working :-(
>
> user_name =3D gets
>
> system ('adduser -m $user_name')

0)
Try that in the Interactive Ruby (irb) and you will get the problem.

1)
user_name is your local defined variable, $user_name is another, global
variable name.
$user_name.nil? # returns true

2)
If you want to use your variable in a string you have to use =20
doublequotes "
instead of singlequotes ' and in ruby you can use the following syntax:
"mystring #{var}"
"mystring "+ var
"mystring " << var

one simple solution with proof of shell injection is:

tries =3D 0
username =3D ""
while not username.match(/\A[a-zA-Z0-9]+\Z/)
tries =3D tries.succ
exit! if tries > 3
print "username: "
username =3D gets.chomp.strip
end
system('adduser -m ' + username)



regards, Sandor Sz=FCcs
--=

Raveendran Jazzez

7/22/2008 6:56:00 AM

0

Usman Akram wrote:

> so please any body tell me that how can i run the system command, by
> using variable in the system() function....?????


Hi Akram,

May be it will help u more

irb(main):003:0> a=`ipconfig`
=> "\r\nWindows IP Configuration\r\n\r\n\r\nEthernet adapter Local Area
Connecti
on:\r\n\r\n Connection-specific DNS Suffix . : \r\n IP
Address. .
. . . . . . . . . . : 192.168.1.45\r\n Subnet Mask . . . . . . .
. . .
: 255.255.255.0\r\n Default Gateway . . . . . . . . . :
192.168.1.1\r\n"


irb(main):004:0> a
=> "\r\nWindows IP Configuration\r\n\r\n\r\nEthernet adapter Local Area
Connecti
on:\r\n\r\n Connection-specific DNS Suffix . : \r\n IP
Address. .
. . . . . . . . . . : 192.168.1.45\r\n Subnet Mask . . . . . . .
. . .
: 255.255.255.0\r\n Default Gateway . . . . . . . . . :
192.168.1.1\r\n"

irb(main):005:0>

Regards,
P.Raveendran
http://raveendran.wor...
--
Posted via http://www.ruby-....

Usman Akram

7/23/2008 4:20:00 AM

0

Hi Raveendran Jazzez,

i am using Ruby for programming in the Linux OS not in Windows, so
plz help me to Run command after Prompting from User... on Linux
operating system, i want to add users to the linux os by using the Ruby
Programming....

from
Usman Akram
email: ajaonchat@yahoo.com
--
Posted via http://www.ruby-....