Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: breaking from a script

by krujos (Curate)
on Jul 31, 2002 at 20:17 UTC ( #186589=note: print w/replies, xml ) Need Help??

in reply to breaking from a script

To exit from the script you can use  exit $errorcode;
I would use a reg ex to match that string i guess. Or check the error level of the adduser command (which is probably a better option for what your trying to do). Do this using perls built in system call.If you try to add a user that already exists it probably wont exit with 0.
if (!system("adduser bob")) { exit 0; } else { exit 122 }

Replies are listed 'Best First'.
Re: Re: breaking from a script
by hostux (Initiate) on Jul 31, 2002 at 21:23 UTC
    hi again, excuse me for my complete stupidity, but how can i integrate that into my script? where would i print the error message in this code?
      if (!system("adduser bob")) { print "system returned 0 everything is ok"; exit 0; } else { print "there was an error, exit and return 127 to the os"; exit 122; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://186589]
[hippo]: Are you any good at perl?

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2018-06-23 09:12 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.