Using automator/applescript to do terminal commands/ssh

hi,
pardon my extreme novice question here, but i was looking for quick & easy ways to create a small applet to basically run a script on a web server to remotely check & update it's IP address with its web host, and also serve internet services to a wifi access point.
here's the basic stuff we usually do in terminal —
my-Computer:~ admin-user$ ssh admin@+{web server IP, ex.: 0.0.0.0}+
+{we then have to wait for it to connect and ask for a password}+
Password: {our input for password}
Last login: Sat Jun 14 15:04:58 2008 from 0.0.0.10
Welcome to Darwin! +{so we are now connected}+
www:~ webserver-admin$ sudo /var/root/IP_update.sh
+{there is then a long output as that script runs and updates the IP with the web host}+
www:~ webserver-admin$ sudo route add -net 0.0.0.0/24 0.0.0.3 +{serve up internet services to a wifi access point, returns output that it was done, failed or already connected}+
www:~ webserver-admin$ sudo /opt/local/sbin/lighttpd -f /opt/local/etc/lighttpd/lighttpd.conf & +{starts up our web server, returns that it was started or already on because port 80 is in use}+
so that's what i want it to do. i thought using automator and the *run shell script* option in it would work, but i can't even get past the first ssh command without an error. i have it set to use /bin/sh, and have tried it with *pass input* setting set either way, *to stdin* or as arguments, but in either case, just on this first line alone, i get the following error —
Run shell script failed
Pseudo-terminal will not be allocated because stdin in not a terminal.
does anyone know why this is happening? how do i get around this and proceed on with my script using automator?
also, if anyone could please give tips about how to use the "pause" to have it wait for prompts over the network (like the "Password:" prompt coming back after an indeterminate number of seconds) and which automator command might be used to pop up a dialogue for user input (like asking for the password), it would be much appreciated. thanx.

You'd want the *do shell script* command in AppleScript for this
http://developer.apple.com/technotes/tn2002/tn2065.html
however you're not going to be able to use it as you would tools such as Expect which allow you to wait and provide additional input on stdin. If all you're doing is updating an IP address why not simplify the entire mess with BIND's dynamic updates?

Similar Messages

  • Use Automator/AppleScript to clean iPhoto Library

    Hello,
    Having read a lot of posts about the use of AppleScript and Automator to do things with iPhoto, I think it's possible to create a script or a processus to clean the iPhoto Library (let say, a copy of it) to eliminate "zombie files" (photos which have not been deleted of the iPhoto Library when emptying the iPhoto trash).
    The script should simply verify, for each file in the "master" folder, il the path of this file is known in the iPhoto database (the data base is in the "AlbumData.xml" file). If it is, the file is kept. It it's not, the file is moved to trash (or to a temporary folder).
    Should anyone create this script ? I should try, but I would need two weeks to do it correctly, and I'm sure someone can do it in 5 minutes... Some help here ? Thanks !

    Hi,
    Try this AppleScript:
    repeat
        set r to (choose file with prompt "Select an iPhoto Library package" default location (path to pictures folder)) as string
        try
            (r & "AlbumData.xml") as alias
            (r & "Masters") as alias
            (r & "Previews") as alias
            exit repeat
        on error
            activate
            display dialog "This package does not contains \"AlbumData.xml\" file or the \"Masters\" folder or the \"Previews\" folder." buttons {"OK"} default button "OK"
        end try
    end repeat
    set iPhoto_Library to quoted form of POSIX path of r
    set AlbDataXML to quoted form of POSIX path of (r & "AlbumData.xml")
    tell application "Finder"
        set newFolder to (make new folder) as string
        set dest to (make new folder at folder newFolder with properties {name:"Images qui ne sont pas dans AlbumDataXML"}) as string
    end tell
    set destF to quoted form of POSIX path of dest
    set file1 to quoted form of POSIX path of (newFolder & "filesPath.txt")
    set file2 to quoted form of POSIX path of (newFolder & "PhotosDataPath.txt")
    do shell script "dest=" & destF & "; tFile=" & file1 & "; tFile2=" & file2 & "; iPhotoLib=" & iPhoto_Library & ";
    grep -A1 '\\(\\<key>OriginalPath<\\|\\<key>ImagePath<\\)' " & AlbDataXML & "  | sed -n  '/<string>/s/^.*<string>\\(.*\\)<\\/string>$/\\1/p' | sort -o \"$tFile2\"
    find \"$iPhotoLib\"Masters -type f \\! -name '.*' >\"$tFile\"
    find \"$iPhotoLib\"Previews -type f \\! -name '.*' >>\"$tFile\"
    sort -o \"$tFile\" \"$tFile\"
    diff -ab  \"$tFile2\" \"$tFile\" | sed -n '/> /s/^> //p' | while read f; do
       name=${f##*/}
       if [ -e \"$dest$name\" ];then
            i=1
            while [ -e \"$dest$name $i\" ];do
                ((i++))
            done
            name=\"$name $i\"
       fi
       /bin/mv -f \"$f\" \"$dest$name\"
    done"
    tell application "Finder"
        activate
        reveal folder dest -- select the folder which contains moved files
    end tell
    This script move every files in the ("Masters" and "Previews") folders which it's path is not in the "AlbumData.xml" file to a new folder on the desktop.
    The grep command get all path in "AlbumData.xml" from the (OriginalPath and ImagePath) keys and put the result in file2.
    The find command get all file's path in the ("Masters" and "Previews") folders and put the result in file1.
    The diff and sed command get all file path in text file1 which is not in text file2
    Before moving file:
    This script check name of the file to not overwrite any file in the destination folder.
    If a name already exist in the destination folder, the script add a space and a number to the end of the filename.

  • Applescript to run terminal command then open application..

    Hey,
    I've installed the add-on to make the Lion Finder sidebar icons colored again, but whenever I reboot my Mac, I have to execute a killall Finder to get those icons back. This also closes TotalFinder, which is an addon I use. So, I want to write an AppleScript which will run on startup, and do those two things: run the Terminal command, and then open TotalFinder.
    I've written:
    tell application "Terminal"
        activate
        do script "killall Finder" in front window
        quit
    end tell
    tell application "TotalFinder"
        activate
    end tell
    This gives me an error stating "Connection is invalid." when running the activate line for TotalFinder. The Terminal command is executed correctly. Any idea why this is? The application is definitely named correctly, its just in my root Applications directory so it should be able to find it, etc. How can I get this working?
    Thanks!

    try this:
    do shell script "killall Finder"
    tell application "TotalFinder"
              try
      activate
              end try
    end tell
    First thing you don't need to open a terminal window to do the killall you can just do to as a shell script.
    Second don't know why TotalFinder gives that message about Connection invalid but it doesn;t seem to affect it any. So putting in the try just eats the error message.
    Ypu may not even need the killall, When TotalFinder starts it restarts the Finder so you may be able to remove the killall
    regards

  • Using Automator/Applescript with Keynote?

    For a series of presentations I'm creating, on practically every slide, I have to delete a picture, then paste the replacement on the slide, resize that item, and reposition it on the slide (at the same location).
    This seemed like a perfect use for Automator, and I recorded my steps in Automator, but I ran into a couple of questions after that.
    1) When I'm in Keynote, I don't see a command to run a script.
    2) I'm looking at the automation that was created, and the workflow includes "Type 600 px into the text field." But I'm concerned that I don't see anywhere in the workflow that specifies what property is being edited at that point.
    Chuck

    Thanks chuck,
    I never thought to use Automator before but may give it a try now.
    I'm pretty new to AS so don't quote me, I know some apps have a File Menu command to run scripts but in general *** are run from the script menu on RHS of Menubar, perhaps you need to activate a pref for that I can'r remeber how I got mine there. Applescripts can be run with Keynote but have limited use. It seems to me there is no property dictionary for Keynote items.
    But i did find this snippet in somebody's applescript suggesting interaction via keyboard shortcuts is possible. Also controlling the slideshow is definitely support by the application dictionary.
    tell application “Keynote“
      activate
    end tell
    tell application “System Events“
      tell process “Keynote“
        keystroke “v“ using {command down}
      end tell
    end tell
    http://piyocast.com/as/archives/537

  • "batch" exporting to aiff using automator / applescript?

    I often find myself prepping a lot of audio for DV editing in Final Cut Pro....exporting audio out of QT to 48khz, 16bit, aiff.
    I'm looking for a way to do this to many files in 1 step....ie: drag and drop a folder/files onto an icon. Automator doesn't seem to have an export action under quicktime. And all i can do in applescript is tinker, at best.
    I downloaded the QT script package from the apple site.. http://www.apple.com/applescript/quicktime/ these seem like a good start, but im havin trouble tweakin them for .aiff audio
    any suggestions for doing this?

    can do this now with automator

  • Using Applescript to execute a Terminal command

    I've looked at the possible answers that come up when I ask this question here, but none really fit my question.
    I want to automate the Terminal command that cleans out obsolete entries in my right-click "Open with" menu, which I have to do often. Rather than copying the command each time I want it, then opening Terminal, pasting it in, etc., is there a way to automate this with Applescript?  Thanks!

    Thanks for the fast reply, Niel. I understand this is a newbie Applescript question, but over the years I have just never used Applescript and other than this one thing, probably won't again.  So rather than take hours to learn it, I hope you don't mind the additional question regarding this.  Do I just put the following into the main Applescript editor?
    do shell script "ls -l ~"
    /System/Library/Frameworks/CoreServices.framework//Versions/A/\
    Frameworks/LaunchServices.framework/Versions/A/Support/lsregister \
    -kill -r -domain local -domain user;
    killall Finder

  • Terminal Commands Using AppleScript

    Hi,
    I have some AppleScripts that access Terminal to send some commands to an Arduino.
    I'm hoping there's a way to keep Terminal from opening a new window each time
    I access it with a command?
    Thanks,
    Carl

    Are you using "do shell script" to execute your commands?  The "do shell script" does NOT open a terminal window.
    The Terminal does not execute commands, it is just a viewing device and keyboard handler for humans.  The Terminal just passes your keyboard input the the shell and/or programs you run from the shell, and displays what the shell and programs run from the shell return.
    The Terminal itself is not needed to run Unix commands.  The "do shell scrpt" is one way to execute commands without the need for the Terminal.

  • How can I use automator to open terminal change directory run a python script?

    Hi all,
    I dont really ever use automator - which may be my big problem - and I am trying to make an apllication that seems fairly simple in theroy. I want something that will lunch terminal, cd to the place where my python script lives and then run it. I have tried a number of suggested ways and can get the terminal to open and the directory to change but cant figure out how to run the script. This is my workflow if i did it manually each time
    - open terminal
    - type cd "the place where my file lives"
    - type python uploadr.py -d
    I can get terminal to open then cd to the right place but cant get the "python uploadr.py -d" to run without an error.
    any help would be very appricated
    thanks!!!
    J

    this is the script I got closest with - I know its something to do with breaking those two commands up but i just dont know how to do it
    on run {input, parameters}
              tell application "Terminal"
      activate
                        if (the (count of the window) = 0) or ¬
                                  (the busy of window 1 = true) then
                                  tell application "System Events"
      keystroke "n" using command down
                                  end tell
                        end if
                        do script "cd /Users/behole/Desktop/FlickrUpload/" & "python uploadr.py -d" in window 1
              end tell
              return input
    end run
    this is the error I get in terminal after I run it
    Last login: Mon Jul 23 15:37:17 on ttys000
    be-holes-MacBook-Pro:~ behole$ cd /Users/behole/Desktop/FlickrUpload/python uploadr.py -d
    -bash: cd: /Users/behole/Desktop/FlickrUpload/python: No such file or directory
    be-holes-MacBook-Pro:~ behole$

  • Creating/running Terminal command with Automator

    I am using Parallels Desktop on my iMac. Occasionally after I shutdown Parallels Desktop/Windows the ram it used is not released back, for example, depending on what I'm running in Parallels Desktop I can use upto around 16GB or ram. Ocassionally when I shutdown Windows and in doing that Parallels Desktop too, this ram level does not go back down. I find that going into Terminal and entering the purge command puts the ram level down to what it was before I loaded up Parallels Desktop.
    I was wondering if its possible to use Automator to create a shortcut that I could then either place on my Desktop or Dock and when needed I could just double click on it and it would then load Terminal and then the purge command?
    Or is there another way that I could automate the purge command?

    I managed to work it out for myself.
    I done the following:
    In Automator I chose Application/Run Shell Script. In the box that appeared in the right side I entered purge. I then saved it to my desired location and I then dragged it onto the Dock for easy access.

  • Terminal command equivalent to Automator's 'set metadata pdf'

    Hi,
    When I make pdf docs I sometimes want to erase my name from the Author metadata, and put something into Title and so on.
    I know that Automator has an action called set pdf metadata, which I have successfully used.  But I would like a Terminal command that I could use instead.
    Googling this question returns suggestions of downloading pdf-manipulation libraries which are too elaborate for me to use.  I'm hoping that Automator is simply utilising a terminal command already built-in.
    Is there such a command?
    Diddles

    A bit of experimenting.
    Given a file temp.pdf in the current working directory . . .
    xattr -w "com.apple.metadata:kMDItemAuthors" "diddles1234" temp.pdf
    writes the string "diddles1234" to the Authors metadata field of temp.pdf.
    xattr -w "com.apple.metadata:kMDItemTitle" "newmetatitle" temp.pdf
    writes the string "newmetatitle" to Title metadata field of temp.pdf.
    However, if you try to put spaces into the string like this:
    xattr -w "com.apple.metadata:kMDItemTitle" "new meta title" temp.pdf
    the title field will not be changed to "new meta title". In fact, if you start with "original title" as the value of kMDItemTitle, successfully change it to "newmetatitle", and then later try to change it again to "new meta title", the value of kMDItemTitle reverts to "original title". The OS appears to "forget" the intermediate change to "newmetatitle".
    As best I can figure, in the event of a failed xattr write command, the original kMDItemTitle is rebuilt from semi-redundant data within the PDF--but more experimentation would be required to prove it. (The same is true of kMDItemAuthors, by the way.) Quick take away: The first two commands above will work if you don't use spaces in the strings to be inserted into the metadata fields. Someone more proficient in UNIX may have a better solution or explanation.

  • Passing files in automator to a terminal command?

    I would like to know if something is possible: I've used automator to sort through a large number of files for specific traits using the 'Filter Finder Items' action. Can I then pass these files, one by one, into a terminal command?
    Specifically, I have a bunch of markdown files that I want to run through the markdown command in the terminal.
    Thanks for any help,

    automator has "run shell script" action. just add that action to the end of your wrokflow with the option to pass input as arguments.

  • Use Applescript variable in Python command line

    Using automator
    Python Shell Output -> [1,2,3,4,5]
    goes to Applescript
    Run Applescript ->
    on run {input}
        set seq_list_appscript to {}
        do shell script "python -c 'for s in input: print s'"
    end run
    it doesn't work . . . how can I call the "input" which is an Applescript variable within the "do shell script" python command line ?

    If the input is actually a list of items, then you would need to iterate through them or coerce the list to something for the command line.  If the input is just the text "[1,2,3,4,5]", then the variable just needs to be inserted into the text of your script statement - the results of the script are returned by the do shell script command, so they can also be assigned to a variable:
        set whatever to (do shell script "python -c 'for s in " & input & ": print s'")
        display dialog whatever

  • I get "App Store Disabled" on my MacBook Pro due to profile issues. What Terminal command can I use to reset profile settings?

    After transferring documents from one MacBook Pro to another I get some weird errors due to settings that seem to have transferred over. One is that the Mac App Store is disabled.
    Are there any Unix / Terminal commands I can use to reset these?

    Forgot Your Account Password
    For Lion/Mountain Lion
        Boot to the Recovery HD:
    Restart the computer and after the chime press and hold down the COMMAND and R keys until the menu screen appears. Alternatively, restart the computer and after the chime press and hold down the OPTION key until the boot manager screen appears. Select the Recovery HD and click on the downward pointing arrow button.
         When the menubar appears select Terminal from the Utilities menu.
         Enter resetpassword at the prompt and press RETURN. Follow
         instructions in the dialog window that will appear.
         Or see Reset a Mac OS X 10.7 Lion Password and
         OS X Lion- Apple ID can be used to reset your user account password.

  • How can I change the "Ask to join new networks" option using a terminal command?

    We are currently switching to a new wireless network throughout our school district and I have pushed commands to connect to the new and remove the old. However, any Macs that have "Ask to join new networks" enabled are jumping over to our unsecure guest network, even if that network has been removed from the list of Preferred Networks. So far the fix has been to remove the guest network from the list of Preferred Networks and then disable Ask to join. The only issue I'm running into now is I have been unable to find a terminal command to change this setting. Once I have the command I can write a script and send that out to all of the Macs.
    So is there a way to disable "Ask to join new networks" using command line?

    sed -i "" 's/Prompt/DoNothing/' /Library/Preferences/SystemConfiguration/preferences.plist

  • Terminal Command, how to set defaults write, make application(s) use directory path where file last saved?

    Does anyone know whether there's a terminal command to make all applications remember/use the last directory/path where I last saved a file?
    For example, let's say there are (10) ten PDF's on a website, and I want to use Preview.app to open and save each file to the same directory.
    Problem is, after each time I save a file, Preview.app doesn't automatically remember/use the last directory where I saved my file(s).
    Forcing me to navigate back to the same directory after each time I save a file; super-annoying.
    But, for some reason, when saving images from the web, Firefox remembers the last directory where I saved the file (jpeg).
    So I'm hoping there's some way, possibly a terminal command to set/force all applications (including Preview.app) to remember/use the directory/path where file(s) were last-saved.
    Anyone?

    Get the third-party utility Default Folder X 4.4.9.

Maybe you are looking for

  • Query regarding Database Level changes

    Hi I am working with a datawarehouse which extracts and populates data overnight across several tables in the reporting layer and across 5 different schemas. The source tables of these remain same (which will get data updated each and every day) but

  • I need that Programm for LV 5.0

    thank you jonnie 5 but there are only programs for LV 6.0 can I download programs for version 5.0 or a LV-Update

  • Can you Pls. explain me

    Hi experts   Can anyone explain me the following query, why they have used query like this, there is no internal table, and how they will process. Will affect the perfomance or not? SELECT * FROM bseg              WHERE belnr = p_vblnr              A

  • Pam_lastlog inactive

    Hi, I have already installed OEL 5.9. I need to implement the funtion of locking an user account if he/she has no login in the last 20 days. pam_lastlog.so has the option inactive, it could be defined in the /etc/pam.d/login auth   required pam_lastl

  • Can't setup sync with Outlook 2003

    When I try to setup the Blackberry desktop to sync with Outlook calendar, the process works fine and it says I did it, but when I hit "finish," it acts as if I haven't done it yet and asks me to do the setup.  Backup is working fine.  This started wh