Quick and easy if then script to determine if an application is running?

I'm getting confused on syntax with an if else statement. I just want see if an app is running and exit 0 if so. If not, then exit 1. I tried a test using TextEdit and I always get a syntax error in the console when running my shell script. Here's what I've got:
ps -axo pid,ucomm | awk '{ if ( $2 == "TextEdit" ) exit 0 [ else exit 1 ] }'
I've been looking at this too long. What am I missing?
Thanks.

Hi Mills,
   You must have stared at it too long. The syntax error is just the square brackets; erase them. If there's only one command "else" works without any grouping symbol. If there is more than one command, the required grouping symbols are braces, "{}" and they would follow the "else" command. By the way Michael, "exit" is an awk command. I swear that I didn't know that either but it is. However oddly, it doesn't do what it says but more about that in a sec.
   The real problem with the awk script is the logic. It would only detect TextEdit if that's the first process listed. This awk script is only going to test the first line because the script is run once for each line and since there's an exit command in each branch of the if statement, it exits the first time it's run. You want something like the following:
ps -axo pid,ucomm | awk '/TextEdit/{ exit 0 } END { exit 1 }'
However, this doesn't work either because the END block is executed despite the "exit" command. Therefore you'd have to do something like:
ps -axo pid,ucomm | awk 'BEGIN{ STAT = 1 } /TextEdit/{ STAT = 0; exit } END { exit STAT }'
That kindof makes Michael's suggestion of "grep" seem more appealing, eh? The exit status of "grep" depends on whether there is a match so it's tailor made to do what you want.
Gary
~~~~
      A farmer with extremely prolific hens posted the
      following sign.
         "Free Chickens. Our Coop Runneth Over."

Similar Messages

  • I have what is hopefully a quick and easy question. I kno...

    I have what is hopefully a quick and easy question. I know almost nothing about this stuff so go easy on me . All I need to do is find out if my DHCP is enabled. I'm having problems with my Xbox 360 and one of the possible problems is this DHCP thing. However I have no idea how to find the settings for my router on my computer. If it helps I have a Wirless model BEFW11S4. Thanks in advance for any help.

    You need to access your router to check if the DHCP is on.  To access the router open your browser and type in http://192.168.1.1 into the address field and hit enter.  That should open the routers log on screen and by default the user is left blank (some routers it is admin) and the password is abmin.  If you changed your routers password as you should for security reasons then use that password.  That will bring you to your routers user interface and on the main set up page should be your DHCP.
    Richard Aichner (Ikester)

  • Lesson for this weekend: Don't trust "quick and easy"

    When they say a process will be simple, quick and easy it really means it may or may not explode in your face!Started out on Friday simply wanting to write a new post for my site and update some old articles. Found out the php upload limit was too low for some of the server photos I wanted to add. No problem, just increase the limit right? Well no. Since the site was still in "Safe Mode" I couldn't change any of the advanced functions. The solution? Switch to Free Mode, billed as a simple process of a few clicks. Lets do this then! Clicked the deceptively easy "Switch to Free Mode" button prepared for a few clicks and getting on with my day. Filled out the information, set the flags I wanted, clicked go.....and it failed. That's fine, it went back to safe mode so I can just retry, right? Fails again. Third times the charm? Nope.At this...
    This topic first appeared in the Spiceworks Community

    When they say a process will be simple, quick and easy it really means it may or may not explode in your face!Started out on Friday simply wanting to write a new post for my site and update some old articles. Found out the php upload limit was too low for some of the server photos I wanted to add. No problem, just increase the limit right? Well no. Since the site was still in "Safe Mode" I couldn't change any of the advanced functions. The solution? Switch to Free Mode, billed as a simple process of a few clicks. Lets do this then! Clicked the deceptively easy "Switch to Free Mode" button prepared for a few clicks and getting on with my day. Filled out the information, set the flags I wanted, clicked go.....and it failed. That's fine, it went back to safe mode so I can just retry, right? Fails again. Third times the charm? Nope.At this...
    This topic first appeared in the Spiceworks Community

  • I want to install just ADOBE photoshop quick and easy. how?

    I want to install ADOBE photoshop quick and easy. how?

    You can download it from this page : http://www.adobe.com/cfusion/tdrc/index.cfm?product=photoshop
    Regards,
    Ravi.

  • E1200 and "Quick and Easy Setup"

    My parents were trying to setup their E1200 router. We had to do a reset (using the button) since we couldn't access the router admin menu (someone had hacked/changed the password). I'm doing this remotely over the phone.
    Now, when they open Internet Explorer, they are getting a"Linksys Quick and Easy Setup" screen no matter what web site they try to get to. They don't have access to the original CD to install Linksys Connect. Mom says that when she clicks on "No CD? Download the software" link, nothing happens. Looks like she's got internet, though, as there's a link to the Linksys forums, and she's seeing updates from the forums."
    I don't know what this screen looks like, but isn't there some way to get past this splash screen? The computer is plugged into the router via a cable, so I'm not sure why they can't access the internet manually. Is there a way to just "disable" the "Quick and Very So Not Easy Setup" and skip right to using the internet?
    Thanks.

    Hi dapupster. I suggest that you let your parents do another reset. Tell them to make sure that they press down the reset button that's underneath the device ( please check the  picture). Let them press it down for 30 seconds while the device is powered on.  Once done, let them unplug the unit, plug it back in and try to access the setup page manually through 192.168.1.1.
    If the challenge remains the same, let them unplug the router from the modem and have them access the 192.168.1.1 page with only the computer that's connected to the router.  Hope the suggestions help.

  • Quick and easy way to learn to use Oracle Spatial?

    Could anyone recommend a quick and easy way to learn to use Oracle Spatial?

    Depends on your style.
    Reminds me of a story a contractor to an IT department I worked in once told me.
    He used to work in Silicon Valley in the '70s and told a story of a company that
    hired a particular programmer who was brilliant but unstable. They used to set
    up a room with a VT100 and a bottle of Tequila. The programmer would arrive
    and set to work. As the Tequila emptied it was replaced. At some point over
    the following days or weeks a scream would be heard from the room, followed
    by a crash as the VT100 went through the window and the programmer disappeared.
    They would replace the window, the VT100, the Tequila and wait till he came back
    from "walkabout".
    "Extreme Programming" '70s tyle!
    OH&S would never allow this nowadays! That, plus Prozac means these sorts
    of programmers are probably very rare!
    Cheers!
    S.

  • Quick and easy fix for linux shell script in 1.2.1.32.13

    Hello, right after installing sqldeveloper in my home directory and linking the script in my bin dir I found a small problem with the shell script for linux.
    I downloaded the "Multiple platforms" zip file.
    here is the fix:
    change "dirname $0" to "readlink -f $0 | xargs dirname"
    with this fix, linking to the shell script won't cause the script to use the bin dir instead of the real directory where sqldeveloper is installed.

    This symptom occur because a 64-bit process that runs on a computer that is running an x64-based version of Windows cannot load the 32-bit .dll files that are required by some program features.
    You may try the following work around:
    You must use the 32-bit version of Windows Explorer. The 32-bit version of Windows Explorer is located in the %windir%\Syswow64 folder on the computer that is running an x64-based version of Windows.
    To use the 32-bit version of Windows Explorer, follow these steps:
    Click Start, click Run, type the following in the Open box, and then click OK:
    Drive_Letter:\windows\syswow64\explorer.exe /separate
    Note The placeholder Drive_Letter represents the drive where the x64-based version of Windows is installed.
    For more information:
    Some Windows Explorer extensions and some Control Panel items are not displayed on computers that are running an x64-based version of Windows
    http://support.microsoft.com/kb/895561#appliesto
    Now check if the issue is resolved.
    You may want to try the following steps:
    PDF thumbnail view via the Acrobat reader:
    1. Run Acrobat Reader. In Reader, click File > Open and navigate to the folder(s) containing your PDF file(s). If necessary, move the slider to show all your PDF files.
    2. Cancel out of Open and exit Reader.
    3. Open Windows Explorer and navigate to the folders(s) containing your PDF file(s).
    4. Click Views and move the slider until you see PDF thumbnails.
    Thanks and Regards:
    Sanjay Manju Suman
    Adobe System Inc.

  • Is there a quick and easy way to reorder de-interleaved data?

    I am collecting 5 channels of data through a DMA FIFO by interleaving, then recording to a TDMS file. When I check it, it's in mostly good order, but there are certain points where the channels get switched. For example, the Channel order when I open the file is 1 2 3 4 5, as expected, for several thousand elements. But at some point, it gets shifted to 4 5 1 2 3, and later 2 3 4 5 1. Left-to-right, they are always ordered correctly, so it's easy to reorder them, but very tedious with millions of elements. I have attached some sample data. I'm looking for A) a way to prevent this or B) some kind of sorting tool or script in LabVIEW or DIAdem that may sort it for me. I'll work on a sorting script in the meantime. 
    I am using LabVIEW 2011 Real-time and FPGA 2011, and the standard TDMS open and write functions. I also have access to DIAdem. 
    Solved!
    Go to Solution.
    Attachments:
    TDMS import-check analog data.xlsx ‏3807 KB

    Sorry for the slow response - 
    I've looked at everything, and so far I can't identify the problem. I believe my code is consistent with the producer-consumer architecture. 
    On the real-time side, I am reading data from the FIFO and writing to the TDMS in the same loop.
    On the FPGA side, analog channels are read, converted to the same fixed-point format with a time stamp in a single-cycle timed loop, and then ordered into the FIFO in a for loop. I have posted the relevant parts below.
    I am using C-series modules in a CompactRIO.
    Attachments:
    top-fpga loop-bottom-rt loop.png ‏26 KB

  • Black and White Preview for all images Quick and Easy can it be done?

    Before I switched to Mac, I used a google program to do my iphoto/aperture like editing called Picasa. Picasa allowed me to change my view to black and white so that all my images looked black and white until I changed my view back. This was GREAT for letting me look at a wedding or a group of images and quickly scan for the ones that looked spectacular in black and white as apposed to color.
    I have been desperately trying to find a setting in Aperture that will allow me to do that so that I can get a super quick preview of everything and mark the ones that I want to really spend time converting to black and white.
    Does anyone know how to do this? I would almost be willing to change my monitor settings to greyscale temporarily if that is even possible.

    What I do is this:
    In the View Menu set Proofing Profile to Gray Tone.
    Then anytime you want to see things in B&W, hit ShiftOptP
    (Pictures are only B&W in Viewer only mode--large or full screen. But you can use the arrow keys to move through a whole album)

  • Quick and easy question about creating folder

    Total Mac newbie with basic question.
    I want to put all my user manuals right on my desktop. All in a folder called user manuals. How would I do this? Smart folder? Just drag 'n drop? how can I quickly find them all?
    Thanks in advance!

    Hi MarieBoyer
    You can easily create a Folder on the desktop, by mouse click + contol to open the contextual menu, where you can choose New Folder, then give it a name.
    Or, more easily still just drag one of the existing folders onto the desktop and use it.
    As for finding all manual documents, they are just documents in general, and may not even have the word manual in their name, so searching by that criteria will in that case miss them. Otherwise you may have to search by each of their names, which would be rather tedious.
    So I suggest, of the manuals that you know of or come across, drag them into your new Folder on the desktop as you find them.
    regards roam

  • Quick and easy way to encode video files?

    With out using another application.

    An easy and simple way you can do this is by using Finder. It might not be the best option, depending on what you need but try it out.
    Control+Click on the file and select > Encode Selected Video Files
    You can choose from 480p, 720p, 1080p, Audio Only, or  Apple ProRes under the Settings drop down menu.
    Then choose whether you want to Encode for higher quality or greater compatability.
    When you have selected your settings the window will tell you the Format, Resolution, Date rate and what it compatible with. The 480p, 720p and 1080p will use H.264 compression which is highly compressed and probably what you want to choose to compress your file.
    After you have selected your settings select the destionation and if you want to delete the source file and click continue.
    Done. Easy and simple, done right in finder.

  • A quick and easy way to add genre to songs in a playlist

    I have a 160mb classic ipod and I want to shuffle only a portion of my total library tracks. I am thinking the best way to do this is to use the Smart Playlist function and shuffle by genre. But if I do that I want to change the genre label or add one to many of my 4000 songs. Is there anyway to do this easily? I tried to select every song in a playlist and right click and use Apply Sort Field, but unfortunately genre is not one of these fields! Any idea?
    Or (although this may be the wrong forum), is the any way, short of making one gigantic playlist, to get my iPod to shuffle among just certain playlists?

    The only way to add to files to a playlist on the player itself is to put them in the queue, then save the queue as a playlist.

  • Is There A Quick And Easy Way Of Avoiding "Stepped" Edges (Aliasing)?

    I am using Compresor 3.0.3 to encode HDV projects to SD DVD.
    I originally tried Exporting QuickTime Movies from FCP but discovered there was terrible shimmering on straight edges and severe judder when panning or if someone walked across the frame.
    Using the "DVD Best Quality 90 minutes" setting smoothed out all the above problems.
    Unfortunately it left noticeable stepping or aliasing on diagonal sharp lines !
    This is much less of a problem than the judder but if possible I would like to get rid of it.
    I have read up about the Bonsai method, but the processing times involved are enormous and not warranted by the slightness of the problem.
    I have also seen an anti-alias slider in Compressor but when I used it the processing slowed almost to a halt. Maybe I was operating it incorrectly ?
    Is there a quick way to get rid of the stepped edges, or is it something everyone has to live with when converting HDV to SD DVD ?
    Ian.

    Yes it's all PAL Kyle. The problem isn't just mine though. It seems to be par for the course. From what I have read, the Bonsai method was devised to overcome it but the actual problem is really so slight, that for amateur work the cure is a bit over the top.
    http://www3.telus.net/bonsai/Step-by-Step.html
    It's too darned hot Luca ! Especially at night.
    Your process seems a bit like the Bonsai method and I'm beginning to think that I might be exaggerating the problem in my mind.
    The aggravating thing is that when I did a straight Export>To QT Movie, although I got terrible judder, there was almost no sign of aliasing ......... which is why I felt there should be a simple solution.
    I'll just have to pray that they bring the prices of Blu-ray down rapidly, so there will be no need to use standard def.
    I am going to experiment with shooting 25PF tomorrow to see if that helps ........ or not.
    Ian.

  • Ok. quick and easy question about my Zen Vision

    i'm thinking that my zen can no longer have anything added to it, although there is about 5 gbs worth of space left. it sucks has sucked for a while, but i'm trying to get over it.
    my brother noticed that in the bottom of it, the part where it connects so you can make transfers and stuff, is bent. i tried unbending it but that didn't work.
    and when i connect it to my comp, it says "overload" and my comp freezes for a bit.
    so that's a sign to get another mp3 player right? it's a shame that this happened. he thinks i was too rough with it.
    i admit that i have spent some time pushing it in when it wasn't properly fitting. but i didn't "see" it then. now looking back, i kinda laugh.
    btw, there are no shops around here to repair the bend to the best of my knowledge..actually, maybe Weiss Hardware...just maybe.

    Yes. LOL You word it so much nicer!
    lol...
    if customer support actually does help, for a nice price, you will be -my new saviour-!
    (My music is literally my life.)
    OK. I checked there. They have an option of support (while the warranty is still good) and another option (that's non-technical).
    I got my first Zen Vision (30 GB) March 2007. Then a replacement (this one) in May 2007. Is it still covered? I have my doubts. :P?

  • Very quick and easy question

    I am making a catalogue, so I need a set of place-holder images which I am able to change he actual image on the following pages after the master one so that I can then move the master image place holders and have all the pages follow accordingly whilst respectivly keeping their different image assigned.
    In other words, is there any way I am able to set a 'place-holder' on master page, then assign different images to the following pages, then if I need to move the layout I can just move the place-holders on the master frame whilst keeping their own set images within the place holders.
    Thank you very much.

    There are a couple of approaches.
    Automatic page numbering is accomplished by putting a text frame on the master page and inserting a current page number marker. You can add additional information or text in the frame if you wish, and format to taste. The number will appear on all pages based on that master.
    Now for the different approaches. The first way is to just add them independently to each master page. However, if you use masters based on one or more other masters to control things that are basically the same (i.e. you have repeating elements on at least two masters, but something else that's different) you can create a "parent" page and put the numbers on that, then base other master pages on the parent, and everything on the parent will be included in the "child" page. You can Ctrl + Shift Click to select and remove an item if necessary. If you want to edit the repeating elements you do it on the parent page, and the change propagates through to the children.
    If you want to have some pages with no numbers you can either make special masters without numbers for them, or just override and delete the number frames on the live pages.
    Peter

Maybe you are looking for