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 }'"

Similar Messages

  • UNIX path AND  Do shell script path with spaces

    I am trying to building a interface with buttons to execute shell commands when the button is pressed. Below press button execute code.
    I am new to AppleScript and Xcode and Interface builder. I have read different post referencing spaces but I still don't understand.
    THIS COMMAND DOESN'T WORK IT'S SOMETHING TO DO WITH SPACES.
    How would I fix this to work.
    on clicked theObject
    do shell script "rm /Library/Preferences/com.netopia.netOctopus\ Agent.preferences"
    end clicked
    This works (Below) no spaces in the path
    on clicked theObject
    do shell script "open /System/Library/PreferencePanes/SharingPref.prefPane/"
    end clicked
    ALL Mac OS X (10.4.6)
    ALL   Mac OS X (10.4.6)  
    ALL   Mac OS X (10.4.6)  
    ALL   Mac OS X (10.4.6)  
    ALL   Mac OS X (10.4.6)  
    ALL   Mac OS X (10.4.6)  
    ALL   Mac OS X (10.4.6)  
    ALL   Mac OS X (10.4.8)  
    ALL   Mac OS X (10.4.8)  

    Camelot's explanation was good, but you don't seem to get it, so I'll take a crack at explaining as well.
    First off, you need to understand what "do shell script" does and does not do. "do shell script" takes a string from AppleScript and passes it to a shell interpreter. It does not check in advance that this string makes sense. (That is impossible to do, in fact.) It just passes it along. The shell interpreter then converts the string into a command, or series of commands, and attempts to run them.
    In AppleScript, quotation marks around something make that something a string. So, for example:
    "rm "
    is a string containing a letter r, a letter m, and then a space. Some commands can also return a string, which can then be stored in a named variable, as for example:
    set a_variable to (the text returned of display dialog "Hi!" default answer "Some text")
    When you wish to put two strings together in AppleScript, you use the & operator, as in:
    "String 1" & "String 2"
    In this example, there is no space at the end of the first string, and none at the beginning of the second, so the result is:
    "String 1String 2"
    All clear so far?
    When a shell interpreter attempts to convert a string into commands, it has to split the string into pieces. A space signifies a break between pieces. In order to put a space into a single item, you can do a number of things. You can put the whole item in quotation marks (single or double), which is known as "quoting":
    '/A/Path/With/A Space'
    or you can put a backslash before the space, which is known as "escaping":
    /A/Path/With/A\ Space
    You can combine quoting and escaping if you do it right. For example, the backslash also lets you use a quotation mark inside a single item which is quoted:
    "/A/Path/With/A Space/And/A\"Quotation/Mark"
    There are further rules and substitutions that sometimes border on the arcane.
    In order to simplify things, Apple created the command "the quoted form of". This command takes a string and returns a new string which is properly set up so that it will be just one item when split up for the command line. It will add quotation marks, backslashes, or whatever.
    So, to put things together:
    "rm " & the quoted form of thePath
    is a way of saying to AppleScript "take the string in the variable named thePath, and quote it for the command line; then stick it on the end of a string containing an r, an m, and a space."
    When you pass this to "do shell script", it will break things up in such a way that it hands thePath to the rm command, which will attempt to remove whatever is represented by thePath. (Adding the "-r" in there just tells the rm command "if this is a directory, get rid of it and all its contents". Otherwise rm will complain if the item is a directory.)
    I think, however, you may just have the path wrong. In one of the spots where you gave the POSIX path, it had a backslash (\) at the end instead of a forward slash (/). As Camelot says, a forward slash means that the item is a directory and not a plain file. But if you really meant the backslash, it suggests that the item is a plain file, but has a space at the end (or some other character that mystifies the command line). It's an escape.
    Try making a new script in Script Editor which says
    ">" & (the POSIX path of (choose file)) & "<" at the end, that's the culprit.
    (And if it won't let you select the file when you run the script, it means that the item is actually a folder.)

  • Exit command in a Shell Script

    I am trying to input an 'exit' command in a shell script. I am running Solaris 8. I have checked all of my documentation on the OS and cannot find the command syntax. Can someone help me? Thanks.

    #!/usr/bin/env bash
    # This a simple bash script outlining the procedures to get macports on OS X
    # to auto update weekly via the ~/Library/LaunchAgents/net.ipatch.macportsUpdate.plist
    # The first step is to update the port files
    echo "Step 1: Update port tree"
    port selfupdate
    # The second step is to upgrade the outdated
    echo "Step 2: Upgrade outdated"
    port upgrade outdated
    # The third step is to remove inactive ports
    echo "Step 3: Remove inactive ports"
    port uninstall inactive
    # The fourth step is to clean the vile
    echo "Step 4: Clean the vile"
    port clean --all vile
    Now invoke your script using sudo, as in:
    sudo ./macportsUpdate.sh
    This way you authentiate once, and from that point forward everything is run a 'root'
    If you do not want to remember to prefix the script with sudo, then you could do the following:
    #!/usr/bin/env bash
    myPortUpdate()
    # This a simple bash script outlining the procedures to get macports on OS X
    # to auto update weekly via the ~/Library/LaunchAgents/net.ipatch.macportsUpdate.plist
    # The first step is to update the port files
    echo "Step 1: Update port tree"
    port selfupdate
    # The second step is to upgrade the outdated
    echo "Step 2: Upgrade outdated"
    port upgrade outdated
    # The third step is to remove inactive ports
    echo "Step 3: Remove inactive ports"
    port uninstall inactive
    # The fourth step is to clean the vile
    echo "Step 4: Clean the vile"
    port clean --all vile
    # Now do all of the above with a single sudo command
    sudo myPortUpdate
    Now you can invoke the script and it will just prompt once for your admin password
    macportsUpdate.sh
    Message was edited by: BobHarris

  • Using launchctl command within a shell script

    I have successfully installed two daemons, and I would like to be able to disable and enable them via shell scripts, called by the daemons themselves. Here is my first shell script:
    #!/bin/sh
    # Testing for presence of a CODEBOY file
    if [ -e "/Volumes/CODEBOY/Change.txt" ]
    then
    osascript '/Users/praxisii/Library/Scripts/MacScript.scpt'
    launchctl unload -w '/Users/praxisii/Library/LaunchDaemons/WaitDaemon.plist'
    launchctl load -w '/Users/praxisii/Library/LaunchDaemons/RunDaemon.plist'
    fi
    The daemon works just fine, running the background, calling this script, which is waiting for me to plug in my flash drive (entitled CODEBOY). When the flash is plugged in, the applescript is called, and the first launchctl command is executed, which disables the WaitDaemon. As advertised, the .plist file is re-written with the Disabled key set to true. The next line (which is supposed to enable the RunDaemon) is never executed.
    Similarly, if the launchctl line is placed before the osascript line, the applescript is never called. It is as if the shell ignores everything after a single launchctl command, which it will execute.
    Any ideas or comments?

    Gary:
    Thank you for the link to the TN2083. Long, but very informative.
    I appreciate all the other comments on this thread. I am an amateur AppleScript/UNIX scripter, and any opportunity to learn more is much appreciated.
    I have completely re-worked my original launchd agent system for automatic processing of a file on a flash drive. Here is the .plist file that I now use:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>Label</key>
    <string>RunOSAscript</string>
    <key>LowPriorityIO</key>
    <true/>
    <key>Program</key>
    <string>/usr/bin/osascript</string>
    <key>ProgramArguments</key>
    <array>
    <string>osascript</string>
    <string>/Users/casdvm/Desktop/AutoFlash.scpt</string>
    </array>
    <key>RunAtLoad</key>
    <false/>
    <key>ServiceDescription</key>
    <string>Runs Applescript directly</string>
    <key>StandardOutPath</key>
    <string>/Users/casdvm/Desktop/AutoFlashLog.txt</string>
    <key>StartInterval</key>
    <integer>25</integer>
    </dict>
    </plist>
    The AutoFlash.scpt is an Applescript that simply uses the Finder to check for the presence of a specific file on the flash drive. If it is there, and a certain script property has a value of 2, then it runs the AppleScript that processes the desired file on the flash drive. Once that is done, the script property is set to 0 (to prevent the processing from happening over and over again.). Once the flash drive is removed, the script property is set back to 2 in anticipation of the next time the flash drive is plugged in.
    It is much simpler than the two agents I was messing with beforehand. I did indeed discover that this .plist needs to be saved in the LaunchAgents folder of my user Library (thanks again for pointing that out, Gary).
    The only problem that I have involves the continuous calling of the Applescript from the launchd agent. As you can see from my .plist file, that AppleScript is called every 25 seconds. I tried setting it up using the OnDemand key, but I kept receiving a re-spooling error of some sort (I don't recall exactly; my notes are sketchy on that phase of testing), so I just decided to have it go every 25 seconds. It really doesn't matter, since I can leave the flash drive plugged in all day anyway, and it only processes the desired file once.
    Thanks again for all the commentary and discussion; I am grateful for the assistance.
    Craig Smith

  • Perl's __END__ doesn't work under Automator's Run Shell Script action

    Howdy,
    I have a large embedded data file in my Perl source file using the _END_ token. It works great at the command line, but when I copy and paste my Perl code into the Run Shell Script code window and execute it, reading the special file handle DATA always returns 0 lines.
    Help?
    -Eric

    Originally I was using $@ to parse a string and get the result pasted by the service. That was a while ago. There, I noticed that some Japanese characters were messed up. Basically all the kana characters that come with voicing markers like が-ga (instead of か-ka) etc. I did not have the time to pursue that issue though.
    Then, last night, I found that a colleague of mine had tried to use $@ to feed to a local dictionary application called ding (http://ftp.tu-chemnitz.de/pub/Local/urz/ding/). His problem was with characters that had umlauts. After verifying how he wrote his action I remembered that I had similar issues with Japanese.
    Basically his command was "/path/to/ding $@"
    That's supposed to use the selected string as an argument to pass to ding, which will launch a Wish application where the string is used as the searched item.
    From Terminal, that works a treat. But the exact same line in Automator (with input as argument, not as stdin) messed the composition and the resulting string was not recognized by ding as a match to what it was supposed to match.
    So, I tried a few things to get to the core of the issue and found that a simple "echo [accented characters]" was enough to reproduce the difference in string handling between Automator and Terminal. That difference is also reproduced on a number of person's machines.
    I have a number of services that basically revolve on "run shell script" actions and involve 3rd party application outputs, preference files etc. so it would not be convenient to show that to you.
    I have sent a mail about this issue to the automator list yesterday too:
    http://lists.apple.com/archives/Automator-users/2011/Jun/msg00004.html

  • [SORRY] exec command problem for shell scripting

    I know this is not an appropriate place to ask questions about shell programming, but I have tried many other places... and no helpful help yet. So, here I am.
    I am writing a simple shell script that would actually execute a java application. However, I want to give the users the option of running it in background. So,
    COMMAND="java blahblah"
    DAEMON="&"
    exec "$COMMAND $DAEMON"
    But, when I run it, it spits out an error message saying something like "Invalid agrument: &".
    Is there a way to exec'ing "java blahblah &" using variables as arguments to "exec" command???
    OR is it even NOT possible?
    This problem seems so trivial, but took a man out of me. :( Please help.
    thanks
    yosep

    execute a java application. However, I want to give
    the users the option of running it in background. It doesn't generally make sense to exec an ansynchronous process, and one can introduce varying errors in this method. Just simply drop the exec. The java process will async off and the shell script will exit leaving no shell process running. Simple as that.
    BTW, you generally exec a java process if you wish to replace the shell with the java process, but then the async request is given at the caller, she who actually calls the script (genarally from an interactive shell).

  • FTP files from Unix box to Windows ( Shell script )--inplemention in Apps

    Hi,
    I have an requirement like need to send files generated at a particular path in the UNIX sever into Windows machine.
    This should be a scheduler( can we create any shell script
    ) for this...
    Note : files generated at Unix move into Windows box....
    Please check and help on this... and let me know if any clarification required on my requirement.
    Thanks,
    Pavan K

    This is relatively easy to do. You will need to write the shell script code and register it as a concurrent program of type "Host". Pl see the Application Developer Guide (for 11i and R12) at http://www.oracle.com/technology/documentation/applications.html for details on how to register a shell script "Host" custom program.
    ML Docs 266268.1, 147455.1, 1013907.6 and 156636.1 have some more info too.
    HTH
    Srini

  • Getting work done from java or shell script

    Hi,
    I have two programs one in java and other is as perl script or batch file. Java program does step 1 of work and perl script do the step 2. Step 2 run only when step completed successfully. And this both program run by script which is part of a big application. Can anybody suggest me if how to do this. Because we can not set environment variaables from a java code, I can not pass any thing to script which is running java and perl code. can any body suggest something.

    Your Java program could call System.exit(0) to end successfully and System.exit(1) if it failed. The shell script can look at the return code and act accordingly.

  • How to run a spool program in unix environment within a shell script

    Hi
    I have written a spool program , which i run from SQL * PLUS
    using
    @'path of the spool file having extension .sql'
    Now i want to include this spool program within the shell script , please help me , how to do it.
    Thanks in advance ..

    user8703472 wrote:
    Thank You Sir for the reply .
    #!/bin/ksh
    ORACLE_SID=<SID>; export ORACLE_SID
    ORACLE_HOME=<ORACLE_HOME>; export ORACLE_HOME
    $sqlplus / as sysdba <<-EOFSQL1 >> output.log 2>&1
    spool /tmp/a.log
    select * from v\$instance
    spool off;
    EOFSQL1
    Please explain me this statement $sqlplus / as sysdba
    and also what a.log contains .
    i have the user id and password for the DB.
    should i write something like this
    $sqlplus -Uusername -Ppassword -Sservername
    i know how to run a procedure from isql(sybase DB)
    Ahh.... but oracle is not just sybase under a different name.
    It would be a good investment in your career to go to tahiti.oracle.com. Drill down to your product and version. There you will find the complete doc library.
    You should spend a few minutes just getting familiar with what kind of documentation is available there by simply browsing the titles under the "Books" tab.
    Open the Reference Manual and spend a few minutes looking through the table of contents to get familiar with what kind of information is available there. Learning where to look things up in the documentation is time well spent on your career.
    For your immediate task, spend a few minutes looking through the SQLPlus User Guide and Reference.
    Then set yourself a plan to dig deeper.
    - Read a chapter a day from the Concepts Manual.
    - Look in your alert log and find all the non-default initialization parms listed at instance startup. Then read up on each one of them in the Reference Manual. Take a look at your listener.ora, tnsnames.ora, and sqlnet.ora files, then bounce what you see there in the network administrators manual.
    Give a man a fish and he eats for a day. Teach a man to fish and he eats for a lifetime.
    But this project , i need to run the spool program from with in a shell script .We see what you mean, but the term "spool program" has no meaning in Oracle and only serves to cloud the issue. I know you are used to using this term with other products, but "When in Rome ...."
    >
    Thank You in advance ..

  • Launchd fails to execute a perl command from a shell script

    Hello all,
    i have a little script that runs rsync. I use perl to add a timestamp to each line of output. Basically it goes like this:
    #!/bin/bash
    rsync -avz $sourceFolder $destinationFolder 2>&1 | perl -e "while(<>){s/^/$(date "+%Y-%m-%d %H:%M:%S") [rsync_backup.daily] /g; print;}"
    Invoking this script from terminal works perfectly! Invoking it via launchd however fails. There is no error thrown, it just seems to not proceed.
    Any help is appreciated.
    Cheers.

    This is the output from the shell:
    /Users/sadmin/Library/rsync_backup
    uid=501(sadmin) gid=20(staff) groups=20(staff),501(com.apple.local.ard_admin),256(com.apple.access_vpn),403(c om.apple.sharepoint.group.2),204(_developer),100(_lpoperator),98(_lpadmin),81(_a ppserveradm),80(admin),79(_appserverusr),61(localaccounts),12(everyone),406(com. apple.sharepoint.group.5),502(com.apple.local.ard_reports),253(com.apple.access_ chat),252(com.apple.access_addressbook),401(com.apple.access_screensharing),504( com.apple.local.ard_manage),503(com.apple.local.ard_interact),250(com.apple.acce ss_afp),404(com.apple.sharepoint.group.3),500(com.apple.access_ssh),257(com.appl e.access_backup),254(com.apple.access_calendar),402(com.apple.sharepoint.group.1 ),255(com.apple.access_mail),251(com.apple.access_smb),405(com.apple.sharepoint. group.4),407(com.apple.sharepoint.group.6)
    de.open-service.rsync_backup.daily.sh
    0
    TERM_PROGRAM=Apple_Terminal
    SHELL=/bin/bash
    TERM=xterm-color
    TMPDIR=/var/folders/A5/A5M1umP6EsKqyAig3q3Bak+++TI/-Tmp-/
    Apple_PubSub_Socket_Render=/tmp/launch-VgtdY6/Render
    TERM_PROGRAM_VERSION=273.1
    USER=sadmin
    COMMAND_MODE=unix2003
    SSH_AUTH_SOCK=/tmp/launch-4Jjpml/Listeners
    __CF_USER_TEXT_ENCODING=0x1F5:0:3
    PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin :/usr/X11/bin
    PWD=/Users/sadmin/Library/rsync_backup
    LANG=de_DE.UTF-8
    HOME=/Users/sadmin
    SHLVL=2
    LOGNAME=sadmin
    DISPLAY=/tmp/launch-219jsQ/org.x:0
    _=/usr/bin/printenv
    rsync is /opt/local/bin/rsync
    perl is /usr/bin/perl
    This is the output via launchd:
    uid=501(sadmin) gid=20(staff) groups=20(staff),501(com.apple.local.ard_admin),256(com.apple.access_vpn),403(c om.apple.sharepoint.group.2),204(_developer),100(_lpoperator),98(_lpadmin),81(_a ppserveradm),80(admin),79(_appserverusr),61(localaccounts),12(everyone),406(com. apple.sharepoint.group.5),502(com.apple.local.ard_reports),253(com.apple.access_ chat),252(com.apple.access_addressbook),401(com.apple.access_screensharing),504( com.apple.local.ard_manage),503(com.apple.local.ard_interact),250(com.apple.acce ss_afp),404(com.apple.sharepoint.group.3),500(com.apple.access_ssh),257(com.appl e.access_backup),254(com.apple.access_calendar),402(com.apple.sharepoint.group.1 ),255(com.apple.access_mail),251(com.apple.access_smb),405(com.apple.sharepoint. group.4),407(com.apple.sharepoint.group.6)
    /Users/sadmin/Library/rsync_backup/de.open-service.rsync_backup.daily.sh
    0
    SHELL=/bin/bash
    TMPDIR=/var/folders/A5/A5M1umP6EsKqyAig3q3Bak+++TI/-Tmp-/
    USER=sadmin
    PATH=/usr/bin:/bin:/usr/sbin:/sbin
    PWD=/
    SHLVL=1
    HOME=/Users/sadmin
    LOGNAME=sadmin
    _=/usr/bin/printenv
    rsync is /usr/bin/rsync
    perl is /usr/bin/perl

  • Execute immediate will work in SQL Block in shell script?

    Hi Friends,
    i am wirting script to get the account id's corresponding to CIF from oracle table and need to pass to procedure.
    Here first_org and last_org are shell variables.
    When i execute the below program it is throwing execute not found.
    Can you please correct me where i made a mistake? and also please let me know how to display some content in below sql block ?dbms_output.put_line or print which need to use and provide me the syntax for both.
    `sqlplus -s crmuser/******@dotis11<<ENDOFSQL
    whenever sqlerror exit 1
    declare
    qstr varchar2(200);
    facid varchar2(20);
    Lacid varchar2(20);
    begin
    qstr:='select ACCOUNTID from accounts where ORGKEY=:1';
    execute immediate qstr into facid using $first_org;
    dbms_output.put_line(facid);
    qstr:='select ACCOUNTID from accounts where ORGKEY=:1';
    execute immediate qstr into Lacid using $last_org;
    dbms_output.put_line(Lacid);
    exec Retail_Otu_Dedup_Account(facid,Lacid)
    end;
    exit;
    ENDOFSQL`
    Thanks,
    Venkat Vadlamudi.

    Hi SY,
    I Included set serveroutput on but i didn't include single quotes for shell variable in execute immediate.
    Now iam able to execute and getting proper o/p.
    Thanks SY for your help...
    and how to print shell variable in above sql block..i tried like this. but throwing error.
    dbms_output.put_line('$first_org');
    dbms_output.put_line('VCIF1320');
    ERROR at line 5:
    ORA-06550: line 5, column 12:
    PLS-00103: Encountered the symbol "." when expecting one of the following:
    constant exception <an identifier>
    *<a double-quoted delimited-identifier> table long double ref*
    char time timestamp interval date binary national character
    nchar
    The symbol "<an identifier>" was substituted for "." to continue.
    ORA-06550: line 6, column 5:
    PLS-00103: Encountered the symbol "=" when expecting one of the following:
    constant exception <an identifier>
    *<a double-quoted delimited-identifier> table long double ref*
    char time timestamp interval date binary national characte
    Thanks,
    Venkat Vadlamudi.

  • Can I add more unix commands to the shell?

    When I was using gnu/linux I used a command called 'get' in the terminal. You used it like this:
    get http://url.com/file.dmg
    Very handy and simple tool. But I just can't find it. Some one here that can point me somewhere?
    Thanks.

    Hi xenix,
    Try using "curl" instead. Like this:cd ~/Desktop ; curl -O http://url.com/file.dmgType man curl in Terminal for more information about it.
    Hope this helps...

  • How to call a HP-UX command or shell script from Forms 4.5

    Does anybody know how to call a unix command or shell script to get a files list of HP-UX server from Oracle Forms 4.5 on client side? I tried to use DBMS_PIPE package to get it done but I failed. Please let me have the solution if anybody knows how. Very urgent!

    I tried the host command before and it just let me shell to the DOS environment but not HP-UX environment as Forms was running on Windows platform. So, I could not run a unix command or a shell script. Is DBMS_PIPE the only way to get it done?

  • Call unix command in sqlplus script

    Hello, I wanna to know how to call a unix command in the sqlplus script.
    For exemple,
    I've a sqlplus script to lauch a oracle report, after the report is generated, I wanne to replace the output file in an other directory.
    So that, I have to call the unix command mv here in the sqlplus script
    How can I do it?**
    I completed my situation:
    I don't have dbms_scheduler untility in my database.
    Thanks a lot for your help
    Edited by: user11930885 on 17 janv. 2010 14:53

    Yes, at the begining, I'll tried the unix shell by calling SQL.
    I've the problem of passing the parameters through.
    It seems to me
    we can use
    Host in the SQLPLUS to run the unix command.
    but I've written it in my sqlplus script, it doesn't work. so I wanna to find an exemple how to use HOST in sqlplus script?
    I would have loved to give you an example..but its not unix on my laptop.
    But what i can tell you is...u should be doing otherway round.
    Not calling Unix commands from SQL but calling SQL's form unix.
    You got shell scripts for that.
    Write a shell script. Login to SQL execute your code.
    exit from sql and then move your file with MV. That's it.
    Do post how far you get after trying this.

  • I can't get a simple "do shell script" in AppleScript to work!

    Hi All,
    I can get simple commands like "do shell script "ls"" or "do shell script "ps"" to work in AppleScript, but I cannot get something like "do shell script "python -V"" to work. (yes, my shell script says: do shell script "python -V" (no double quotes!))
    This is driving me nuts!
    Can anyone help?
    - Jon

    python -V appears to direct its output to stderr. Try
    do shell script "python -V 2>&1"

Maybe you are looking for