terminal command files

Posted:
in Genius Bar edited January 2014
i have made a couple of command files for the terminal, so i can just double-click them and the command is executed. these work great but i want to do a multiple command, and am not sure how to do it.



eg



cd /Applications/foo

./start &



any ideas?

Comments

  • Reply 1 of 5
    it's actually quite simple. just put the extra commands across several lines in the the .command file.



    example:

    [code]cd /Applications/foo

    ./start&</pre><hr></blockquote>



    and, if ur default shell is something sane, like bash, tcsh, csh, sh, zsh or almost any other *nix shell, then can use semicolons ( instead, or beside the new-lines. (the default shell for osx, i think, is tcsh)

    example:

    [code]cd /Applications/foo;

    ./start&</pre><hr></blockquote>

    [code]cd /Applications/foo;./start&</pre><hr></blockquote>



    i assume, of course, that you're referring to .command files (files whose name ends in ".command").
  • Reply 2 of 5
    othelloothello Posts: 1,054member
    yeah, .command files are exactly what i am talking about.



    but, when i do what you suggest i get:



    [matt-powerbook:~] matt% /misc/start_zope.command; exit

    logout

    [Process completed]



    so it doesn't run...



    pants!! (thanks for the help though)
  • Reply 3 of 5
    first off, that is the correct output. i tested it with my own .command files.



    there are a number of things which could be at fault, if its not getting the desired results. first, make sure the file has the right commands in it. if ur willing to post it on this forum, i can verify it for you. second, since in ur initial example you suggested that you were going to background a process, you could check 'top' or 'ps aux' to see if that process is there. type:

    [code]ps aux | grep 'start'</pre><hr></blockquote>

    (replace start with actual name of program)

    if that command outputs a line or two onto the terminal, then the process is, infact, running.



    another way to make sure ur script is doing what its supposed to, is to put an echo an the end of it. try adding this on a new line after all ur commands:

    [code]echo "Script completed successfully";</pre><hr></blockquote>

    Now, with the echo line, next time you run the .command file, it should say "Script completed successfully" when its over.
  • Reply 4 of 5
    othelloothello Posts: 1,054member
    here is the command i'm trying to execute:



    cd /Applications/Zope-2.5.1-MOSX

    ./start &



    i basically want to start-up my zope instance by clicking a file rather than typing in the terminal.



    the .command file has the right permissions and is set to run the terminal (i have another .command file which i use to ssh into my webserver which works fine. it only has 'ssh user@foo.com' as the command.)
  • Reply 5 of 5
    did you try the 'ps aux ...' line, or adding the echo at the end?



    the ssh script you made runs a program in the foreground. so, when u run it, you have to exit 'ssh' for the .command file to really be finished. but this script (which ends with './start&') puts a process into the background (thats what the ampersand [&] means). so, control goes back to the .command file immediately, and with nothing left to do, it exits. the program you are trying to run, may in fact be running, which you can verify by typing

    [code]ps aux | grep 'start';</pre><hr></blockquote>into a new terminal. if you want the .command file to remain open, you could take the ampersand off the './start&' line. then the command file will only close when 'start' finishes running. depending on what 'start' does, you may or may not want that to happen.
Sign In or Register to comment.