Background job in shell script?

I run these three commands on the command line to start my Linux gnome session.
But when I embed them in a script, as follows, it is as if control is never returned from starting the first command in the background. Obviously I am ignorant of some basic principle of scripting ... not quite sure what to search for.
I'd be grateful if someone could explain what I need to do to adapt the commands to a shell script.
#!/bin/bash
Xephyr -screen 1910x1140 2> /dev/null :3 &
export DISPLAY=:3.0
ssh bothy gnome-session 2> /dev/null
}

@etresoft thanks for taking the time to suggest a solution.
Actually I think it's a matter of timing, so I think evaluating `jobs -p` waits for the background process? to start, before executing the next scripted command whereas before, the X11 client on bothy was sending to a local X11 server that hadn't had time to completely initialise. When doing it on the command line it has plenty of time while human is inputting next command.
#!/bin/bash
# gnome - open a gnome-session on a remote system's X11 client
# Usage: (eventually! script evolving)
# gnome host -D DISPLAY
# Example:
# gnome bothy -D 3
Xephyr :3 -screen 1910x1140 2> /dev/null &
echo `jobs -p`
export DISPLAY=:3.0
ssh aegir@bothy gnome-session 2> /dev/null 1> /dev/null &
echo `jobs -p`
The above works now. Plus I can see the processes to kill when I'm finished with the X11 session.
Actually didn't make any difference having the argument :3 in the more sensible place but it makes more sense to me as it did to you although, as I say, it works just fine on the terminal command line when the display number argument is written at the end of the line .... but I don't really understand the syntax of that command. Thanks again.

Similar Messages

  • Output format of sqlplus commands under shell script

    hi experts
    Can you help with some problems please?
    1.) I try to run shell script from dbms_scheduler, which runs sqlplus and the output of sqlplus commands is written to file using command spool. To this point everything is running ok.
    My problem is, that output of this file is: (e.g.)
    SQL> PROMPT ****************USERB******************
    ****************USERB******************
    SQL> --SELECT sid
    SQL> -- FROM v
    SQL> -- WHERE audsid = SYS_CONTEXT('userenv','sessionid');
    But I don't want the whole first line in the output file. I only want the output of this command, like on the second line.
    2.) How Can I write two outputs from sqlplus using command spool running at the same time into one file?
    Like in first issue described above. The main sqlplus create a job and this execute the background sqlplus using shell script. But both, the main and the background sqlplus are written to output file at the same time. But only one is written into. But I want the both outputs in the file.
    How Can I do that, if I can?
    Thanks a lot.

    user9357436 wrote:
    hi experts
    Can you help with some problems please?
    1.) I try to run shell script from dbms_scheduler, which runs sqlplus and the output of sqlplus commands is written to file using command spool. To this point everything is running ok. then why are you here?
    My problem is, that output of this file is: (e.g.)
    SQL> PROMPT ****************USERB******************
    ****************USERB******************so remove PROMPT line from the file
    >
    SQL> --SELECT sid
    SQL> -- FROM v
    SQL> -- WHERE audsid = SYS_CONTEXT('userenv','sessionid');
    But I don't want the whole first line in the output file. I only want the output of this command, like on the second line.
    2.) How Can I write two outputs from sqlplus using command spool running at the same time into one file?you can not do so.
    Like in first issue described above. The main sqlplus create a job and this execute the background sqlplus using shell script. But both, the main and the background sqlplus are written to output file at the same time. But only one is written into. But I want the both outputs in the file.
    How Can I do that, if I can?Can't.
    Now what?
    >
    Thanks a lot.Why using DBMS_SCHEDULER to invoke OS script to run sqlplus that runs SQL statements?
    this is like making THREE Left Turns, instead of single Right Turn.
    Just invoke PL/SQL procedure that does what needs to be done.

  • Applescript: display dialog while doing shell script

    Hello there,
    I'm making an applescript app for my company, and had  a question.
    The functionallity of the app is working great, but there is a certain step which can take up to several minutes.
    This can give the user the feeling that nothing is happening and things are stuck.
    Is there a possibility to display a dialog as long as the action (shell script) is running?
    Something along the lines of "Now performing action X. please wait...)
    Thanks for your thoughts!
    Grtz

    With regular AppleScript you can start the shell script in the background (see do shell script in AppleScript) and then put up a dialog, although you would have to periodically check to see if the shell script is finished.  In Lion, the AppleScript Editor has a Cocoa-AppleScript template that you can use (kind of a wrapper application that lets you use various Cocoa methods without having to use Xcode), in which case you could put up an indeterminite progress indicator and then do the shell script.
    AppleScript Studio is deprecated as of Snow Leopard, but there are some AppleScriptObjC in Xcode tutorials at MacScripter.  An additional source of information and templates is macosxautomation, but they seem to be having some server problems at this time.  I also have a Progress Window template application example, it can be downloaded here.

  • Error executing shell script using dbms_scheduler

    I have a job running which executes a shell script,which fails with following error :
    SQL> SELECT additional_info
    2 FROM user_scheduler_job_run_details
    3 WHERE log_date = (SELECT MAX (log_date)
    4 FROM user_scheduler_job_run_details);
    ADDITIONAL_INFO
    ORA-27369: job of type EXECUTABLE failed with exit code: No such file or directory
    STANDARD_ERROR="mkdir: Failed to make directory "/export/home/bwsolaris/abc"; Permission denied"
    This are contents of my shell script
    #!/bin/ksh
    /bin/mkdir /export/home/bwsolaris/abc
    Can anyone suggest me some way out of it?
    Thanks in advance!!!

    Does oracle still creates a user nobody"nobody" is a "standard" Unix/Linux lowly privileged user, which is used by DBMS_SCHEDULER by default.
    You should change permissions on /export/home/bwsolaris, e.g.
    $ chmod 777 /export/home/bwsolaris
    or use a different directory, where everyone has access, for example /tmp.
    Or take a look at Metalink Note:391820.1 - Scheduled Job Running Shell Script Fails With ORA-27369

  • Calling Procedure/Package in shell script

    how to call a package / procedure in a unix shell scripts. also how to schedule jobs in shell scripts.

    That's usually accomplished by run sqlplus from shell script.
    http://www.oracle-base.com/articles/misc/OracleShellScripting.php
    Crontab can be used to schedule jobs in unix.
    http://www.adminschoice.com/docs/crontab.htm

  • Shell Script to grep Job File name and Log File name from crontab -l

    Hello,
    I am new to shell scripting. I need to write a shell script where i can grep the name of file ie. .sh file and log file from crontab -l.
    #51 18 * * * /home/oracle/refresh/refresh_ug634.sh > /home/oracle/refresh/refresh_ug634.sh.log 2>&1
    #40 17 * * * /home/oracle/refresh/refresh_ux634.sh > /home/oracle/refresh/refresh_ux634.sh.log 2>&1
    In crontab -l, there are many jobs, i need to grep job name like 'refresh_ug634.sh' and corresponding log name like 'refresh_ug634.sh.log '.
    I am thinking of making a universal script that can grep job name, log name and hostname for one server.
    Then, suppose i modify the refresh_ug634.sh script and call that universal script and echo those values when the script gets executed.
    Please can anyone help.
    All i need to do is have footer in all the scripts running in crontab in one server.
    job file name
    log file name
    hostname
    Please suggest if any better solution. Thanks.

    957704 wrote:
    I need help how to grep that information from crontab -l
    Please can you provide some insight how to grep that shell script name from list of crontab -l jobs
    crontab -l > cron.log -- exporting the contents to a file
    cat cron.log|grep something -- need some commands to grep that infoYou are missing the point. This forum is for discussion of SQL and PL/SQL questions. What does your question have to do with SQL or PL/SQL.
    It's like you just walked into a hardware store and asked where they keep the fresh produce.
    I will point out one thing about your question. You are assuming every entry in the crontab has exactly the same format. consider this crontab:
    #=========================================================================
    # NOTE:  If this is on a clustered environment, all changes to this crontab
    #         must be replicated on all other nodes of the cluster!
    # minute        (0 thru 59)
    # hour          (0 thru 23)
    # day-of-month  (1 thru 31)
    # month         (1 thru 12)
    # weekday       (0 thru 6, sunday thru saturday)
    # command
    #=========================================================================
    00 01 1-2 * 1,3,5,7 /u01/scripts/myscript01  5 orcl  dev
    00 04 * * * /u01/scripts/myscript02 hr 365 >/u01/logs/myscript2.lis
    00 6 * * * /u01/scripts/myscript03  >/u01/logs/myscript3.lisThe variations are endless.
    When you get to an appropriate forum (this on is not it) it will be helpful to explain your business requirement, not just your proposed technical solution.

  • Triggering background job event from Unix script

    Hi all,
      I am having one question regarding triggering of background job in SAP using Events from Unix script. Is this possible? If so, can anyboy provide some sample code related to Unix script and how do we communicate to SAP from Unix system. Actually, here the backend of R/3 system is MSSQL. I am having a program in R/3 system which is scheduled as a background job based upon event trigger. I want to trigger that even from the unix script.
      Appreciate for your help in advance.
    Thanks,
    Adithya K

    Hi,
    Check if this can help you
    http://help.sap.com/saphelp_sm32/helpdata/en/fa/096e6b543b11d1898e0000e8322d00/content.htm
    Regards,
    Atish

  • How to run 3 job(a,b,c) parallel in unix shells script and after will complete d will start  and we have to handle the error also

    how to run 3 job(a,b,c) parallel in unix shells script and after will complete d will start  and we have to handle the error also

    032ee1bf-8007-4d76-930e-f77ec0dc7e54 wrote:
    how to run 3 job(a,b,c) parallel in unix shells script and after will complete d will start  and we have to handle the error also
    Please don't overwhelm us with so many details!  
    Just off the top of my head ... as a general approach ... something like
    nohup proca
    nohup procb
    nohup procc
    while (some condition checking that all three procs are still running ... maybe a ps -ef |grep  )
    do
    sleep 2
    done
    procd
    But, we'd really need to know what it is you are really trying to accomplish, instead of your pre-conceived solution.

  • Shell Script gives error when run through cron job.

    Hi,
    The following shell script runs without any problem when executed manulally.
    USED=$(df -h /arch | tail -1 | awk '{print $5}' | cut -d '%' -f 1)
    if [ ${USED} -gt 90 ]
    then
    find /arch/AUBUAT/ -type f -mtime +0 | xargs rm
    find /arch/AUBMIG/ -type f -mtime +0 | xargs rm
    fi
    But the same gives below error when called from a cron job:
    /backup/arch_test.sh: syntax error at line 1: `USED=$' unexpected
    We are running following version:
    bash-3.00$ uname -a
    SunOS uaeaubdbdr01.aub.af 5.10 Generic_141444-09 sun4u sparc SUNW,SPARC-Enterprise
    Kindly assist.
    Thanks
    Edited by: user13362786 on Apr 20, 2011 4:36 AM

    Hi,
    When I used #!/usr/bin/sh now even the manul execution of the script fails with the same err:
    bash-3.00$ ./arch_test.sh
    ./arch_test.sh: syntax error at line 2: `USED=$' unexpected
    And when I used #!/usr/bin/ksh the manual execution runs fine but again when the script is run from cronjob it now give dirrect err:
    /backup/arch_test.sh[2]: df: not found
    /backup/arch_test.sh[2]: tail: not found
    /backup/arch_test.sh[2]: cut: not found
    /backup/arch_test.sh[2]: awk: not found
    /backup/arch_test.sh[3]: test: argument expected

  • Unix master shell script to run jobs in parallel with dependency

    I need a master shell script which would call the following shell scripts as per below order. Kindly note that if any shell script fails then the master shell script should abort.
    Level 1     PRODUCTS
         SP_ROST_DLY_STG_lD
         SP_ROST_DLY_ITG_lD
    After Level 1 completes run below two shell scripts in parallel:
    Level 2     SP_IDL_EDGE_CON_POSTN_STG_Ld ,     SP_IDL_EDGE_ACCT_POSTN_STG_LD
    After Level 2 completes run below shell scripts as per the seqeunce and in parallel:
    Level 3     SP_IDL_EDGE_ACCT_STG_LD ,     SP_IDL_EDGE_CONT_STG_LD
         SP_IDL_EDGE_ACCT_STG_VAL ,     SP_IDL_EDGE_CONT_STG_VAL
         SP_IDL_EDGE_ACCT_ITG_Ld ,     SP_IDL_EDGE_CON_ITG_Ld
    After Level 3 completes run below shell scripts as per the seqeunce and in parallel:
    Level 4     SP_IDL_EDGE_CONT_POSTN_ITG_LD ,     SP_IDL_EDGE_VISITS_LD
         SP_IDL_EDGE_ACCT_POSTN_ITG_LD ,     SP_IDL_EDGE_VISITS_DTL_LD

    can i avoid using set -e and use some other method so that if there is an error in previous job then the next job is not triggered.Sure, but it is ugly.
    The below is not the only way to do this...
    Wrap every place you start another script with:
    $ if ! MYSCRIPT; then
        echo Script MYSCRIPT failed. >&2
        exit 1
    fibut the wrapper for parallel scripts is even worse:
    $ MYSCRIPT &
    $ MYSCRIPT_JOBNO=$!
    $ MYSCRIPT2 &
    $ MYSCRIPT2_JOBNO=$!
    $ MYSCRIPT_STATUS=`wait ${MYSCRIPT_JOBNO}`
    $ if [ ${MYSCRIPT_STATUS} -ne 0 ]; then
        echo Script MYSCRIPT failed. >&2
        exit 1
    fi
    $ MYSCRIPT2_STATUS=`wait ${MYSCRIPT2_JOBNO}`
    $ if [ ${MYSCRIPT2_STATUS} -ne 0 ]; then
        echo Script MYSCRIPT2 failed. >&2
        exit 1
    fi
    ...Now, doesn't a simple 'set -e' look much better?

  • PLSQL job and unix shell scripting

    I want to be a plsql developer, now reading job ads for the technical requirement.
    This is a typical plsql job ad:
    "Technically those applying MUST have a minimum 5 years Oracle PL/SQL design and development experience combined with 3 years Informatica/ ETL exposure. You should be comfortable working off Unix platforms and associated *Shell Scripting* and database performance tuning. Experience with vendor products surrounding the compliance area such as Mantas or Actimize is highly beneficial. "
    Generally, do plsql developers work with shell scripting on a basic level, like echoing, saving files, looping etc, well, this level? : Unix Programming for dummies [http://www.amazon.com/Programming-Dummies-James-Edward-Keogh/dp/0764500619|http://www.amazon.com/Programming-Dummies-James-Edward-Keogh/dp/0764500619] . Er...this kind of of shell programming is very easy, why bother even putting the requirement in the ad? It's like saying you need to know primary school maths for the job.
    Or plsql developers work with unix programming at this kernel programming level, like semaphores, signal, UNIX Systems Programming: Communication, Concurrency and Threads? [http://www.amazon.com/UNIX-Systems-Programming-Communication-Concurrency/dp/0130424110/ref=sr_1_6?ie=UTF8&s=books&qid=1256350650&sr=1-6|http://www.amazon.com/UNIX-Systems-Programming-Communication-Concurrency/dp/0130424110/ref=sr_1_6?ie=UTF8&s=books&qid=1256350650&sr=1-6]
    I got plsql and sql tuning requirement under control, now need your help to know what level of expertise is required for unix shell scripting. What plsql developers generally do with unix shell scripting? Can you recommend a book to read?
    Many advance thanks.

    Generally, do plsql developers work with shell scripting on a basic level, like echoing, saving files, looping etcYes.
    Or plsql developers work with unix programming at this kernel programming level, like semaphores, signal, UNIX Systems Programming: Communication, Concurrency and Threads? Generally speaking, No.

  • Tips for parsing xml in a shell script?

    Hello,
    I'm writing a shell script to extract info from an xml file to create various text files that share data in the form of custom entities declared at the top of the document (product id, name, version, copyright date, etc.). So far I'm using xmllint which is working well. I'm extracting text for my project files using xmllint --shell:
    <pre style="padding-left: .75ex; padding-top: .25em; padding-bottom: .25em; margin-top: .5em; margin-bottom: .5em; margin-left: 1ex; max-width: 80ex; overflow: auto; font-size: 10px; font-family: Monaco, 'Courier New', Courier, monospace; color: #222; background: #eee; line-height: normal">echo cat lls_cd_product/plist | xmllint --noent --shell xyz.xml | sed -e '1d; $d'</pre>
    This is working well, but --shell mode adds an extra line to the beginning and end which I let sed cleanup, but then I need to strip the enclosing tags as well.
    Xmllint does a good job of filling in my entities with the exception of MacRoman bullet characters that I've entered as &#165;. These are just converted to the same entity in hex, &#xA5;. I suppose I can replace those with sed, but that's starting to feel kludgey.
    I'm beginning to wonder if there may be a better way to do this. I'm not very familiar with XSL, but I am considering ramping up on that.
    Any suggestions would be welcome.
    Cole

    etresoft wrote:
    It may be a few hours before I get time to work on it.
    Or not.
    Here is your XML file:
    <?xml version="1.0" encoding="UTF-8"?>
    <info>
    <ver>2.1.1</ver>
    <tag>abc</tag>
    <name>Product Name</name>
    <filename>productname</filename>
    <copyright>2008</copyright>
    </info>
    This generates the cd product file:
    <?xml version="1.0"?>
    <xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
    <xsl:output method="xml" indent="yes" version="1.0" encoding="UTF-8"
    doctype-system="http://www.apple.com/DTDs/PropertyList-1.0.dtd"
    doctype-public="-//Apple Computer//DTD PLIST 1.0//EN"/>
    <!-- You could access addition data from some other XML file. -->
    <!-- <xsl:variable name="data" select="document('data.xml')/data"/> -->
    <xsl:template match="info">
    <plist version="1.0">
    <dict>
    <key>hfs-openfolder</key>
    <string>.</string>
    <key>hfs-volume-name</key>
    <string><xsl:value-of select="name"/></string>
    <key>hide-hfs</key>
    <string>./{Norton,*.txt,*.exe,.inf}</string>
    <key>hide-iso</key>
    <string>./{PDS,*Rename,readme,.Volume*,Norton*,*icns,Run*.app,Icon*,Desktop*,TheFolder}</string>
    <key>hide-joliet</key>
    <string>./{PDS,*Rename,readme,.Volume*,Norton*,*icns,Run*.app,Icon*,Desktop*,TheFolder}</string>
    <key>iso-volume-name</key>
    <string><xsl:value-of select="tag"/></string>
    <key>joliet-volume-name</key>
    <string><xsl:value-of select="name"/></string>
    </dict>
    </plist>
    </xsl:template>
    </xsl:stylesheet>
    and this generates the Mac read me file in XML:
    <?xml version="1.0"?>
    <xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
    <xsl:output method="xml" indent="yes" version="1.0" encoding="UTF-8"/>
    <!-- You could access addition data from some other XML file. -->
    <!-- <xsl:variable name="data" select="document('data.xml')/data"/> -->
    <xsl:template match="info">
    <!-- You don't have to deal with these entities anymore. You should be
    able to save this xsl file in UTF-8 format and just type in the
    bullets. But the entities work too. -->
    <readme_mac><xsl:value-of select="concat(name, ' ', ver)"/>
    Copyright <xsl:value-of select="copyright"/>, Laureate Learning Systems¨, Inc.
    Minimum System Requirements:
    ¥ 300 MHz or faster PowerPC, Intel or better CPU
    ¥ Mac OS 8.1 or later, including any Mac OS X
    ¥ 64 MB available RAM
    ¥ 60 MB available disk space
    </readme_mac>
    </xsl:template>
    </xsl:stylesheet>
    This one will output the readme in HTML:
    <?xml version="1.0"?>
    <xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
    <xsl:output method="html" indent="yes" version="4.0" encoding="UTF-8"/>
    <!-- You could access addition data from some other XML file. -->
    <!-- <xsl:variable name="data" select="document('data.xml')/data"/> -->
    <xsl:template match="info">
    <!-- You don't have to deal with these entities anymore. You should be
    able to save this xsl file in UTF-8 format and just type in the
    bullets. But the entities work too. -->
    <html>
    <head>
    <title><xsl:value-of select="concat(name, ' ', ver)"/></title>
    </head>
    <body>
    <xsl:value-of select="concat(name, ' ', ver)"/>
    Copyright <xsl:value-of select="copyright"/>, Laureate Learning Systems¨, Inc.
    Minimum System Requirements:
    300 MHz or faster PowerPC, Intel or better CPU
    Mac OS 8.1 or later, including any Mac OS X
    64 MB available RAM
    60 MB available disk space
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>
    Yes. I do enjoy XSL quite a bit

  • How to wrap import and export in a Unix shell script?

    Hi all,
    I want to write a simple korn shell Unix script to kick off export and import
    for our Oracle 10g refresh databases. Do any of you have a script to do this?
    The goal would be:
    1. Take export using exp of 10 tables in PROD database on database server1
    for the prod schema user
    2. Use sftp or scp to copy over the export dump file to database server 2
    3. Use a shell script to import the dump file into TEST database server for schema
    test
    4. use nohup to run the export and import in background through cron job
    We are running Oracle 10g Release 2 on Red Hat Linux.
    Thanks,
    Ben Prusinski

    Wouldn't it be easier to have both databases in your tnsnames.ora file. Then you can export and import on the same server without copying the files to another server.
    script:
    exp <username>/<password>@PROD file=<file>.dmp log=<explog>.log owner=prod
    imp <username>/<password>@TEST file=<file>.dmp log=<implog>.log fromuser=prod touser=test
    run this script as: nohup <scriptname> &
    Since you are on oracle10g you can also use datapump (expdp and impdp) for faster exporting and importing, but I do not know the syntax by heart

  • Running Shell Script from

    Dear Friends!
             I have one requirement, I have to trigger Unix Shell script from ABAP program.   but only twist in the story is my SAP box is not in Unix system so I cant use external command execute function module.  Is any one come accross to such scenario ? Please advice on this that How we can do this task.
    I have one idea like
    I can make shell script from ABAP put into FTP directory of Unix using webservice and schedule the background job or something in UNIX so after some time it get executed but not sure on this. if we can achieve this in real time it will be really cool compare to background job or something.
    Please give me your expert advices. Any help from you will be greatly appreciated.
    Thanking you and Regards
    Naeem

    I use PI for this.

  • Shell script to empty a folder...

    Hi, I want to write a shell script that deletes the contents of a folder called temp, I want the script to run at 12:00am every evening. I do not want to run the script everytime I log in to the server, any thoughts on the best way to accomplish this?

    Daniel--
    Definitley don't use a background process. There are lots of ways to accomplish this. If you really want it to happen at midnight, use cron. Just create your script and then use the crontab program to edit your crontab:
    crontab -eTo run a job every night at midnight, it would look something like this:
    0 0 * * * /full/path/to/scriptOr use the periodic tasks that run daily at 3:15AM. If you puut your script in the /etc/periodic/daily folder, it will be run as part of the daily scripts. Any status information your script prints out will be printed to the daily.out log.
    Be aware, though, that scripts run from that directory (or from for that matter), don't get the same environment variables as you'll have in the shell. So be careful about paths to files. Especially since you want to use it to erase files.

Maybe you are looking for

  • Some questions on HD upgrade/replacement for late 2008 UMBP

    Hello All - it's HD upgrade time. My Late 2008 15" UMBP's 250GB Hitachi hard drive is beginning to fill up so I've purchased a new Hitachi 500GB HD to install into my machine. I got it at OWC Here is the drive: http://eshop.macsales.com/item/Hitachi/

  • How can I get the keynote to work?

    I am trying to play the keynote on the Apple website but it wont play.Any help?

  • Cannot move objects with Selection Tool

    Having problems moving a selcected with Selection Tool: the selection does not move. Also cannot isolate imported picture as it always seems to be selected, even when deselected: Selection Tool always activates first layer even though I'm on another

  • Product / BOM structure

    Manufacturing involves 2 processes - A and B. In process A, multiple SKU are processed (group of SKU are processed as one material). In process B, each SKU is processed individually. This scenario is like variant configuration in production order (in

  • To-Do's linked with Mail or iCal

    I understand the current iPhone software syncs the calendar component of iCal but not the To-Do's. I am wondering if anyone has heard if the revisions to Mail or iCal in the new OS X (Leopard) will bring this functionality into the iPhone? KLB