Finishing up this Do shell script

Hey guys,
I am trying to wrap up this script, no pun intended. My goal is to run four commands. A DHCP release, a pause, a renew, then output of the DHCP server address. I am fine until the last command to get the output of DHCP server address.
Within the terminal, I can run ipconfig getpacket en0, and it will give me tons of info, including the DHCP server.
The Apple script errors out on that last command, and I would love the info grepped and outputted to a dialog box or a terminal window. Here is what I have so far. Any help is appreciated.
do shell script "sudo ipconfig set en0 BOOTP" with administrator privileges
do shell script "/bin/sleep 60"
do shell script "sudo ipconfig set en0 DHCP" with administrator privileges and password
do shell script "ipconfig getpacket en0" with administrator privileges and password
I am doing this as we are moving to a different DHCP server, and my boss wants to verify the cutover happened.
Thanks,
DB

Hi DB,
   If I understand the "with administrator privileges" modifier correctly, it uses sudo without need for you to put it in the command. Thus if I'm correct in that regard, your use of sudo is redundant, although as you know, it will work. Second, the "ipconfig getpacket en0" command works for me without using sudo. I'm sure that's not true of the release/renew commands but it appears to be true of the last one. Of course it doesn't hurt to run the command as root so that certainly isn't the problem either.
   You could test this yourself but the problem appears to be that the exit status of the ipconfig command you posted is 1, which means an error. I know it returns nice data but the AppleScript interpreter sees the error and thus itself fails. There is a simple workaround that is a hack but it works. You can put more than one command in a "do shell script" statement by separating the commands with a semi-colon. Thus you can follow the ipconfig command with another command that succeeds. For instance, the following should work:
do shell script "ipconfig getpacket en0;:"
Here I've added a colon after the semi-colon. The colon is a shell command that does nothing but always succeeds.
   Of course the correct approach would be to figure out why ipconfig returns an error and fix the problem. I apologize but I don't use the command much so don't know what is causing the error.
Gary
~~~~
   Whoever dies with the most toys wins.

Similar Messages

  • Reg: UNIX shell script at File Adapter

    Hi all,
    I am doing a File to file scenario and using command line arguments in Sending file adapter. I am using UNIX shell script ".sh" file for executing the command.
    I gave the following path at "Run OS command before message processing" parameter:
    /temp/xidelivery/send/FILOSC004_shell.sh
    and this file contains following code:
    <b>#!/user/bin/sh cp /temp/xidelivery/send/FILOSC004_in.txt /temp/xidelivery/send/FILOSC004_input_copy4.txt</b>
    I put the source file, FILOSC004_in.txt and shell script files at the respective paths.
    If I give "cp" command directly in command line it is working fine. But I could not execute this with shell script. Can any body give me the reason where I gone wrong.
    Regards,
    Pavani.

    Hi,
    can you try this,
    bash /temp/xidelivery/send/FILOSC004_shell.sh
    let me know.
    hey you can check the blog below to catch the OS errors,
    /people/michal.krawczyk2/blog/2005/08/17/xi-operation-system-command--error-catching
    Prasad Babu.
    Message was edited by:
            PrasadBabu Koribilli

  • PL/SQL function - unix shell script

    Hello,
    I have an application that calls a unix shell script This unix shell script calls a oracle function in the PL/SQL package. For example,
    In package pkg_test, there is function f_test. This function returns pls_interger.
    How can I write a unix shell script to return the value from the oracle function, so that the application can get the value from the unix shell script?
    Many thanks.

    Thank you for your response.
    The Oracle functuion pkg_name.proc_name will return different values, 0, 1, 2, 3 in diffefrent conditions.
    The unix script, myscript.ksh calls pkg_name.proc_name.
    The other application will call myscript.ksh and this application will need to get the values 0, 1, 2, 3 from myscript.ksh.
    Can we make it without using the unix shelll function?
    Thanks.
    Edited by: slsam01 on Jun 2, 2009 9:21 PM

  • How to exec. stored procedure having out parameter value in shell script ?

    Hi Gurus,
    I am writing a shell script which is calling a SP having out parameter as varchar2.
    So how can i do this in shell scripting ? (I am a new in shell scripting)
    a simple example is preferred.
    Thanks
    Sandy

    So how can i do this in shell scripting ? Assuming you want to assign the out parameter value to a shell variable, here's a small example :
    SQL> select ename from emp where empno=7902;
    ENAME
    FORD
    SQL> create or replace procedure show_name (
      2     v_empno in number,
      3     v_ename out varchar2)
      4  is
      5  begin
      6     select ename into v_ename from emp
      7     where empno = v_empno;
      8  end;
    SQL> /
    Procedure created.
    SQL> exit
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options
    $ cat show_name.sh
    ENAME=`sqlplus -s test/test << EOF
    set pages 0
    set feed off
    var V1 varchar2(30);
    exec show_name($1, :V1);
    print V1
    exit
    EOF`
    echo $ENAME
    $ ./show_name.sh 7902
    FORD
    $

  • How to submit "active users" standard report using shell scripting

    Hi All,
    Greetings.
    I want to submit the "Active Users" standard report in Sysadmin responsibility using a shell script.
    I also want to pass a parameter named email to this..
    can anyone help me do this?
    Thanks in Advance,
    Bhaskar

    Hi Bhaskar,
    You can achieve this by shell scripting either by scripting via CONCSUB utility (invoked from OS) or you can use the FND_SUBMIT package (through PL/SQL package), and in the script itself you can create the outputs or any hardcode messages to a file, and then mail the output to your desired mail address.
    If you use mail or mailx command using the OS utility then you can even send mail to external users which should not necessarily be a registered EBS users.
    Google, Forum Search and metalink will provide you loads of articles on how to use CONCSUB and FND_SUBMIT packages.
    Thanks &
    Best Regards,

  • Designating literal characters in "do shell script"

    (Also posted in UNIX forum)
    If, in Terminal, I do this:
    echo 1/2/3 | sed 's/\/2\// and /g'
    I get the expected result, which is:
    1 and 3
    But if, in AS, I do this:
    do shell script "echo 1/2/3 | sed 's/\/2\// and /g'"
    I get this error message:
    Expected “"” but found unknown token.
    If I change the AS command to:
    do shell script "echo 1/2/3 | sed 's//2/ and /g'"
    I get this error message:
    sed: 1: "s//2// and /g": bad flag in substitute command: '/'
    (Of course, if I change the AS command to:
    do shell script "echo 1/2/3 | sed 's/2/ and /g'"
    I get the expected result, which is:
    1/ and /3
    but this is no help in getting rid of the forward slashes, which is what I want.)
    I think this also happens with some other "special" characters surrounding "2". A Google search would seem to indicate this as a well-known dilemma, but I haven't stumbled across a clear solution -- is there one?

    osimp,
    I also replied in the Unix forum. But here's a little more explanation.
    Your command string gets "evaluated" twice... first by AppleScript and then by the shell. Since backslash characters are escape characters in both AppleScript and the shell, you want literal backslashes passed from AppleScript to the shell so when the shell gets the command string it will process them as escape characters in front of the forward slashes.
    So you need to escape the backslashes (double-backslash) in AppleScript so they'll be passed to the shell as literal backslashes (single-backslash). Then when the shell evaluates the string the single-backslashes will be treated as escape characters.
    <pre>
    do shell script "echo 1/2/3 | sed 's/\\/2\\// and /g'"
    </pre>
    Steve

  • Do shell script with SED

    I've used this a lot and have never observed this behavior; if it's normal I must really not have been paying attention.
    If I have a file (/Q.txt) which contains
    cnow
    cis the time
    cto call
    and do this: do shell script "sed 's/c//' < /Q.txt"
    the result is
    now
    is the time
    to call
    which is what I would expect.
    HOWEVER, if use this approach:
    set T to "cnow
    cis the time
    cto call"
    do shell script "echo " & quoted form of T & "| sed 's/c//'"
    the result is
    now
    cis the time
    cto call
    (I can't use the global form, as that will remove other instances of "c")
    The only way I can think this will happen is if "echo" removes the returns from T; but looking at the output of echo by itself the result looks okay. And the paragraph count of that result is the same as for T.
    What dumb thing am I doing now?

    Your issue is with the newlines (or other invisible characters) that are getting used. When I copied your example script, it worked as expected (the first match is replaced on each line). I don't know why the Script Editor would use different newline characters, but you can see from the following example how SED works with various ones:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #FFDDFF;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    -- use a FF as the newline
    set T to "cnowc" & (ASCII character 10) & "cis the timec" & (ASCII character 10) & "cto callc"
    do shell script "echo " & quoted form of T & "| sed 's/c//'"
    --> correct
    -- use a CR as the newline (same as 'return')
    set T to "cnowc" & (ASCII character 13) & "cis the timec" & (ASCII character 13) & "cto callc"
    do shell script "echo " & quoted form of T & "| sed 's/c//'"
    --> same as your result
    -- the 'backslash-n' is a newline character that gets converted at compile time
    set T to "cnowc\ncis the timec\ncto callc"
    do shell script "echo " & quoted form of T & "| sed 's/c//'"
    --> correct
    -- replace all
    set T to "cnowc\ncis the timec\ncto callc"
    do shell script "echo " & quoted form of T & "| sed 's/c//g'"
    </pre>
    Since I can't see what you are using to generate the newlines (but they look the same), I am guessing that the wrong newline is getting placed in there. Copying from various sources may wind up with the different newline characters.
    Message was edited by: red_menace

  • Do Shell Script .. with Administrator Privileges ... ?

    hi everyone!
    I have a script that have multiple lines like this:
    do shell script " ... " with administrator privileges
    do shell script " ... " with administrator privileges
    Mac OS X 10.4 does it right(?) by asking ONCE for an admin login/password, and would run both lines above ... but 10.2 (and 10.3?) asks TWICE for the password using the same code. What am I doing wrong? I want all versions 10.2-4 to ask only once ... Any ideas?
    Thank you!!
    Cass

    If you would prefer that your script would not ask for a password to get admin privileges, then this uses the keychain:
    set aVariable to do shell script DefinedAsVariable password getPassw() with administrator privileges
    -- The Handler --
    The following handler assumes you have a password in your keychain called ASPW (could be anything you want) saved as a generic key. To do that, open your Keychain Access (in Utilities) application, choose file New, and in the sheet give it a name, enter your account name and type the password you want to use (your admin password in this case). OK. Now find the new password and double-click it. Under the attributes tab change Kind to generic key (it will be Applications). This makes for a fast search because there aren't many of them. Switch to the access control tab and select the "Allow all applications to access this item" button. Enter your admin password in the dialog that appears, and you are done. The first time you run the script, you'll have to click "Always Allow" in the dialog that appears - perhaps several times. After that, it won't ask.
    to getPassw()
    tell application "Keychain Scripting"
    launch
    tell current keychain to ¬
    tell (some generic key whose name is "ASPW")
    return password
    end tell
    end tell
    end getPassw

  • Intermittent "Power Shell Script failed to run" after installing SQL MP 6.5.4.0

    We recently installed the SQL MP.  One thing I am struggling with is this "Power Shell Script failed to run" that occasionally comes up, but, not always on the same server, and not always at the same time. 
    It says it ran past the configured timeout of 300 seconds. 
    The post that seemed to have me on the right track was
    https://social.technet.microsoft.com/Forums/en-US/c539a55d-dd48-438f-b7d5-06ed2cecf6e9/powershell-script-failed-to-run-alerts-from-sql-management-pack-6410?forum=operationsmanagergeneral
    However, even after getting one of the several scripts that have been generating the error, out of the extract management pack, it has parameters that need to be fed to it that I have no idea what they are....
    Example.  ActiveRequestsDataSource.ps1 requires $computername, $connectionstring, $tcpport, $sql_wmi_namespace, and $servicename. 
    The computername is easy enough...  so is tcpport.  but, the others... not so much. 
    I am fairly certain I will be able to run these manually, if I just knew the parameters...  I am also fairly certain we are getting these because at the time of the check, resources on that server are tied up for one reason or another. 
    Can someone please help?  This is killing me. 

    Hi,
    As this issue happens after you installing SQL MP, so from my point of view, it seems like caused by the runas account for the SQL MP is not configured well, I would like to suggest you follow the article below to configure runas account for the management
    pack:
    Configuring Run As Accounts and Profiles in OpsMgr – A SQL Management Pack Example
    http://blogs.technet.com/b/kevinholman/archive/2010/09/08/configuring-run-as-accounts-and-profiles-in-r2-a-sql-management-pack-example.aspx
    Regards,
    Yan Li
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]

  • Running Plsql procedure using shell script

    Dear All,
    Dear All,
    I have to generate reports weekly by using a plsql procedure.
    For Exapmle : My Proc name is Weekly_report(i number).
    Here i is the argument for which i need to run the proc 7 times as follows
    exec weekly_report(1)
    exec weekly_report(2)
    exec weekly_report(3)
    exec weekly_report(4)
    exec weekly_report(5)
    exec weekly_report(6)
    exec weekly_report(7)
    I need to run them parallely at a time so that time taken will be less. Is there any way doing this through shell script.
    Thanks in asdvance.

    damorgan wrote:
    I can't think of anything in the Oracle world left in the dustbin of history I miss less than shell scripts.
    Why work in another language, why work in a tool that is non-portable, why have to deal with SysAdmins when dbms_scheduler is many times more capable?
    Definitely DBMS_SCHEDULER. Shell scripting is obsolete with perhaps only a few very rare exceptions.+1: shell scripts suck.
    DBMS_Scheduler allows you to setup the report procedures as programs that are executed at the same time in a single job (as steps in a scheduler chain). you can also setup email confirmation based on them successfully completing. All good stuff and not difficult to do.

  • Shell script to modify the xml attribute

    Hi All,
    I am new to shell script. I have to add one command in a shell script file to modify xml file.
    +*<oa:link id="iSupplier" adminCustomizable="true" destination="http://server1/" />*+
    I have to modify the destination attribute of above mentioned tag_ in a xml file. Anybody can suggest me how can we do this in shell script.
    Thanks in advance..
    Regards,
    Purushoth.

    Thanks for feedback. Compiling this product under Enterprise Linux 5 seems problematic. Binary package is available from the EPEL repository (Fedora)
    http://fedoraproject.org/wiki/EPEL
    su -c 'rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm'
    # yum install xmlstarlet
    Edited by: Dude on Nov 25, 2010 7:31 AM

  • Translating working UNIX command to "do shell script"

    A few days ago LittleSaint and Gary Kerbaugh (UNIX discussions) suggested an approach for text positioning which appears to work flawlessly in Terminal. The UNIX version is:
    awk -v str_x="140 280" -v str_y=abcdef 'BEGIN{ printf "%-13s%s\n", str_x, str_y }'
    Now, I'm trying to use this in AS as a "do shell script". Clearly, some changes are needed (characters escaped, punctuation changes, etc.), but I've been unable to nail down exactly what those are (assuming it's even feasible).
    Ideas?

    How about this:
    do shell script "awk -v str_x=\"140 280\" -v str_y=abcdef 'BEGIN{ printf \"%-13s%s\\n\", str_x, str_y }'"

  • Complex shell script command

    HI Experts
    can anybody know what this complex shell script command is doing .. i know its looking for some character at some point but exact explanation will be good for learning.
    egrep "^.{292}[CFOPRA][EPR]$" dn.dat
    Thanks

    A simple example can often demonstrate how things work:
    # cat sample.dat
    xABCDE1
    xABCDE2
    ABCDE3
    ABCDE4
    xDBCEA5
    xDBCEA6
    # egrep "^.A" sample.dat
    xABCDE1
    ABCDE4
    Above matches lines that begin with any character followed by an "A".
    # egrep "^.{2}A" sample.dat
    xABCDE2
    Above matches lines that begin with any 2 characters followed by an "A".
    # egrep "^.{2}[AD]" sample.dat
    xABCDE2
    xDBCEA6
    Above matches lines that begin with any 2 characters followed by an "A" or D".
    # egrep "^.{6}[345]$" sample.dat
    ABCDE4
    xDBCEA5
    Above matches any lines ending with "3", "4" or "5",
    provided it's the 7th character.
    # egrep "^.{5}[345]$" sample.dat
    ABCDE3
    Above matches any lines ending with "3", "4" or "5",
    provided it's the 6th character.
    # egrep "^.{6}[EA][26]$" sample.dat
    xABCDE2
    xDBCEA6
    Above matches any lines ending with combinations of "E2, E6, A2, A6",
    provided the combination starts at character position 7.
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Wait for a "do shell script" command to finish

    i have an applescript that has to call a few external applications. i currently do this by setting the exact syntax of the external command in a string variable, then issue a "do shell script cmd" (seen many examples across the net using this standard)
    my applescript continues beyond these commands. how do i set the applescript to either wait for the above external command to finish, or not?
    regards
    jingo_man

    Usually AppleScript will wait for a shell script to complete before it continues, but adding an ampersand (&) at the end of the shell script command will make it run in the background, which allows the AppleScript to continue. See Technical Note 2065: do shell script in AppleScript for more information.

  • How to solve this problem in shell script: unexpected end of file

    Hello,
    I need to connect to each databases listed in /etc/oratab and check which database is shutdown(or mounted-only) and which database is opened to accept connection. However, following shell script gives me this error message:
    $>./check_is_db_runing.sh
    ./check_is_db_runing.sh: line 39: syntax error: unexpected end of file
    Could anyone please help me to solve this problem, why the code (line 29 to 32) does not work in the LOOP? It works without the LOOP.
    Thanks in advance!!!
    1 #!/bin/bash
    2
    3 LOGDIR=/data03/oracle/dbscripts
    4 ORATABFILE=/etc/oratab
    5
    6 cat $ORATABFILE | while read LINE
    7 do
    8 case $LINE in
    9 \#*) ;; #comment-line in oratab
    10 *)
    11 ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
    12 if [ "$ORACLE_SID" = '*' ] ; then
    13 # NULL SID - ignore
    14 ORACLE_SID=""
    15 continue
    16 fi
    17
    18 # Proceed only if last field is 'Y'
    19 if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y" ] ; then
    20 if [ `echo $ORACLE_SID | cut -b 1` != '+' ]; then
    21
    22 ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`
    23 PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/etc
    24 export ORACLE_SID ORACLE_HOME PATH
    25 LOGFILE=$LOGDIR/check_$ORACLE_SID.log
    26 touch $LOGFILE
    27 #echo $LOGFILE
    28
    29 $ORACLE_HOME/bin/sqlplus -s "/ as sysdba" << EOF > $LOGFILE
    30 select * from global_name;
    31 exit
    32 EOF
    33
    34 fi
    35 fi
    36 ;;
    37 esac
    38 done

    This code works ie. generates logs with sql result - slightly modified to be runable:
    #!/bin/bash
    LOGDIR=/tmp
    ORATABFILE=/etc/oratab
    cat $ORATABFILE | while read LINE
    do
    case $LINE in
    \#*) ;; #comment-line in oratab
    ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
    if \[ -z $ORACLE_SID \] ; then
    # NULL SID - ignore
    ORACLE_SID=""
    continue
    # Proceed only if last field is 'Y'
    else
    ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`
    PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/etc
    export ORACLE_SID ORACLE_HOME PATH
    LOGFILE=$LOGDIR/check_$ORACLE_SID.log
    touch $LOGFILE
    #echo $LOGFILE
    $ORACLE_HOME/bin/sqlplus -s "/ as sysdba" << EOF > $LOGFILE
    select * from global_name;
    exit
    EOF
    fi
    esac
    done

Maybe you are looking for