Check shell script status

The following question is related to the same application I am developing in the thread named "Open something on first launch?", if that may help you answer it.
How exactly do I check to see if hidden files are being displayed or not?
This:
set shellcheck to do shell script "defaults read com.apple.Finder AppleShowAllFiles"
if the result returned in shellcheck = FALSE then
display dialog "FALSE"
else if the result returned in shellcheck = TRUE then
display dialog "TRUE"
end if
or this:
set shellcheck to do shell script "defaults read com.apple.Finder AppleShowAllFiles"
if shellcheck = false then
display dialog "FALSE"
else if shellcheck = true then
display dialog "TRUE"
end if
doesn't seem to work...

The first thing to realize is that if the defaults parameter doesn't exist, the script will return an error. Therefore your code needs to include a try/end try block to catch that error.
Secondly, if the key/value does exist, defaults will return '1' if it's true, or '0' if it's false.
Therefore, your script should look more like:
try
  set shellcheck to do shell script "defaults read com.apple.Finder AppleShowAllFiles"
  if shellcheck = "0" then
    display dialog "FALSE"
  else if shellcheck = "1" then
    display dialog "TRUE"
  end if
on error
  display dialog "Preference value does not exist"
end try

Similar Messages

  • Unix Shell Script to check file Format

    Hello
    I am New to shell scripting.Please help me to write a script for the below condition.Any help is highly appreciated.
    I will get a text file every month like the one below
    Sample file
    Payslip.txt
    ========
    EMPID EMAIL PCTAG#
    4946:[email protected]:151207
    4978:[email protected]:154434
    5091:[email protected]:160784
    5208:[email protected]:153601
    5211:[email protected]:158963
    5218:[email protected]:156967
    5247:[email protected]:153760
    5250:[email protected]:160078
    5276:[email protected]:154693
    I should check for the below conditions in the above file
    Conditions:
    =======
    1.File should be seperated by colon(;)
    2.EMPID should not be null
    3.Email address and pc tag# should be null if it is missing
    4.No empty record should be there
    All the above four conditions should be checked
    If any one of four conditions are not met then the file is invalid and it should exit with status saying that file is invalid.
    If all the four conditions are met it should say that the file is valid
    Any help is highly appreciated.It is urgent.
    Thanks in advance
    Manoj

    Try this :
    error()
    {       echo -n "Line "$NR "  "$LINE "  "       >>$STATUS
            echo $1                                 >>$STATUS
    NR=0
    STATUS=/tmp/status.txt
    rm -f $STATUS
    cat Payslip.txt | while read LINE
    do
            NR=`expr $NR + 1`
            ### Check colons ###########
            if [ ! "`echo $LINE | grep :`" ]; then
                    error "No colon"
                    continue
            fi
            EMPID=`echo $LINE | awk -F: '{print $1}'`
            EMAIL=`echo $LINE | awk -F: '{print $2}'`
            PCTAG=`echo $LINE | awk -F: '{print $3}'`
            ### Check null line ###########
            if [ ! "$EMPID" -a ! "$EMAIL" -a ! "$PCTAG" ]; then
                    error "Null line"
                    continue
            fi
            ### Check null EMPID ###########
            if [ ! "$EMPID" ]; then
                    error "No Empid"
                    continue
            fi
    done
    echo
    if [ -f $STATUS ]; then
            cat $STATUS
            echo
            echo "File is Invalid"
    else
            echo "File is Valid"
    fi
    echo

  • Shell Script for db status

    Dear experts,
    I have to do the below requirments can you please help me on this,
    i have to check the database status on every 2 hour intravel, i need a shell script to check the database status whether up or down, if the status is up i have to call .sql file , if the status is down the mail will be sent to dba team with mailx functionality, can any one plz help me on this? this requirment needs to be used only shell script code. thanks in advance
    Os is AIX
    db version 11.2.0.2

    I can think of a few ways this can mislead...
    expired password
    mail problems (both mail not working, and too much mail on Monday...)
    network problems (for example, db can be up and working, but that client can't get there - false negative)
    Client dead, or process can't start (false postive - no mail, therefore no problem)
    Login storm (so only some new connections rejected, random false negative or false positive)
    Listener down or related login problems, device with executables offline, out of horsepower - users still working, but no new logins.
    Multiple problems (I've seen more than once, both phone lines and power fail, no notification sent)
    Error not discriminatory enough - the email should at least send the error it got.
    False positive - only script can get to db, users can't with modern tiered architecture.
    client tnsnames.ora not available or corrupted.
    Nothing wrong with having a script, you just have to watch the requirements and definitions. More sophisticated solutions have problems too. In the end you have to decide what the operational priorities are. Two hours down might be OK at 4AM but not at 6. You also don't want to stretch the limits of an UPS.

  • Refreshing a status bar with a shell script

    Hello,
    I use the lemonbar to display some informations about my system. The lemonbar
    use a shell script to display informations. Sometimes I want to refresh my status bar.
    To be brief: is it possible to refresh the status bar without checking for example every 2 seconds with
    a "sleep 2" command ?
    Let's take an example: with my window manager I switch
    from desktop 1 to desktop 2. At the moment I use a sleep command and I refresh the information
    every 2 seconds. Is there a way my shell script get notified about the switch from desktop 1 to desktop 2 and can refresh
    the information in my status bar ? So it would be not necessary to execute a sleep command every two seconds.
    Until now I found nothing. An idea is to react to a keyboard shortcut (the switch from desktop 1 to desktop 2), but
    I don't know if it's possible.  Perhaps something with a signal ? I also know some X events are generated by creating or closing windows
    for example. I don't know if reacting to X events would be another possibility.
    Thank you!

    kokoko3k wrote:Eg: if a WM writes the current desktop in a file, then you can just watch that file via inotify and do an event driven action.
    I will keep it in mind. I have to check, but it's possible I can use that solution.
    kokoko3k wrote:As a side note: how do you switch "desktops" without a WM? Was it just an example?
    Yes, it was an example. If I change in the future I could use the solution for the chosen wm.
    But at the moment I can create groups. Each groups get a number and I can raise or hide all applications
    in that group. So it's the same problem.

  • Shell Script CONCSUB Utility Completion Status

    Hi All ,
    I'm trying to call a concurrent program from a shell script using CONCSUB utility. Is there a way to wait for the concurrent program to be completed in the shell script and get the RETCODE value which the concurrent program is returning?
    My Current Code is something like this:
         v_conc_request2=`CONCSUB XXCONC/xfunct1on '"'$APPL_SHORT_NAME'"' '"'$RESP_NAME'"' \
                             $userName WAIT=15 CONCURRENT XXXX XXCXXXXXX \
                             '"'$CURRDATE'"' '"'ALL-XXXPRD'"'`
         v_conc_id2=`echo $v_conc_request2 | cut -f3 -d" "`
         echo "v_conc_id2: "$v_conc_id2
    if [ $? -ne 0 ]; then
              errorMessage="Error while submitting the concurrent request for Downstream"
              echo $errorMessage
              echo $errorMessage | mailx -s "Automated Currency Rates Load Failure- DownStream" -n "$email"
              exit 1
    else
    echo "Concurrent Program Successfully submitted for ALL Downstream Environments"
         fi
    fi
    This is working fine but its only getting the request id i want to get the return status of the concurrent program. Since my logic is based on the return status of the concurrent program i need to do some logic.
    Appreciate your help on this one.
    Thanks in advance!

    for those who wanted the solution, here it is..
    v_conc_request1=`CONCSUB XXCONC/xfunct1on '"'$APPL_SHORT_NAME'"' '"'$RESP_NAME'"' \
    $userName WAIT=15 CONCURRENT XXXX XXXXGEDLRTLD \
    '"'$CURRDATE'"' '"'XXXXX'"'`
    v_conc_id1=`echo $v_conc_request1 | cut -f3 -d" "`
    echo "v_conc_id1: "$v_conc_id1
    CONC_STATUS=`sqlplus -s $1 <<!
    SET feedback OFF;
    SET head OFF;
    SET pages 0;
    SET lines 300;
    SET feedback OFF;
    SET term OFF;
    WHENEVER SQLERROR EXIT FAILURE;
    SELECT phase_code || ',' ||
    status_code
    FROM FND_CONCURRENT_REQUESTS fcr
    WHERE request_id = $v_conc_id1;
    exit
    !`
    export PHASE_CODE=`echo $CONC_STATUS | cut -d',' -f1`
    export STATUS_CODE=`echo $CONC_STATUS | cut -d',' -f2`
    echo phase_code : $PHASE_CODE
    echo status_code : $STATUS_CODE
    if [ "$PHASE_CODE" = 'C' ] && [ "$STATUS_CODE" = 'E' ]; then
    errorMessage="Error while submitting the concurrent request for XXXX"
    echo $errorMessage
    echo $errorMessage | mailx -s "Automated XXXCurrency Rates Load Failure- XXXX" -n "$email"
    exit 1
    else
    echo completed normally
    fi
    Edited by: 876473 on Sep 8, 2011 6:29 AM

  • Unable to check Null condition in a Shell Script

    Hi,
    When I am using to check the Null Condition To check for a Running Java Process its failing to check.
    I am using variable in a shell script
    DPID=$(ps -ef |grep - i java|grep -v grep)
    if [ "$DPID"="" ' ];then
    else
    fi
    If the DPID has Null value then its getting executed but if the DPID has value its not getting into the else part of the loop
    Thanks and Regards

    You could try -c to make grep return a count of matches, then check if this count is zero or not.
    DPID=`ps -ef |grep - i java|grep -vc grep`
    if [[ $DBID -ne 0 ]]; then
    else
    fi

  • Exit status running java classpath in a unix shell script

    I'm new to putting java into unix scripts. I have a java classpath running inside of a unix shell script. During my testing it will error with java.io.FileNotFoundException error, which I know why that is, but when I set in my unix shell script this to see the right exit status of success/fail, it always shows a 0 for success when that isn't really the case. Below is the two lines I have set to capture the exit status and just display that exit status for now.
    notifycode=$?
    echo $notifycode
    I have these 2 lines above on a line right below my java command in my unix shell script. How can I get my unix shell script to show the right exit status if the java classpath command fails? Thanks for any help.

    That's Java code, it says "End this Java application and send return code 1 back to the shell". As for how the shell gets the return code from the application, that's a question about your shell and not about Java programming, no?

  • Checking database availability with shell script

    can anyone help with a script that checks for database availability before 10 P.M and 7 A.M at 5 minites interval and starts a SQL Load of a table once the db is available.
    I have no Shell script experience at all but I can amend an already written script.
    Please Help !!

    Dear Timothy,
    Within the Oracle software you have installed on your machine, there is a script called "dbstart" within the <ORACLE_HOME>/bin directory. This script provided by Oracle can be easily modified to check whether the server is up and should help solve your problem.
    Ciao!

  • How to check from a shell script that a particular software is installed

    Hai friends
    I want to write a shell script which has to check whether a particular software is installed on the machine, or not. If installed, then what version is it using and the get the version number and which type of installer is it? i mean is it a .rpm installation or a tar.gz installation.
    how can i check this from a shell script. If any of you have any idea please give me a sample script to check this
    Thank you

    @Raja_Abilash
    I don't think this is a right thread & right forum to POST this question.
    better go ahead with forums related to LINUX.

  • Script to check RDP connection status

    Hi all,
    Could anyone provide me a script to check whether multiple remote servers are able to RDP or not. I just want to check the connectivity status. I have checked with past threads available in form, but none has worked for me. Powershell or Batch or VBS scripts
    ... anything would be good....
    I am not that much good at writing scripts.. So please help me.
    Thanks in Advance..
    Vinay..

    Run this script on one of the servers:
    Get-Wmiobject -Class Win32_Terminal -Property *
    It should return a number of information including, fEnableTerminal. For servers that have RDP enabled, fEnableTerminal should be 1, for the servers with RDP not enabled, fEnableTerminal should be 0.
    Once you can confirm that this is the case, I will provide the full script to run this on multiple servers with input from AD query of text file
    That still won't tell you if the TS is accessible.  PortQry or Net Tcp are the fastest and easiest ways to do this.
    Your code also only orks on WS2008R2 and later but, s posted, ill not work on any system.  Have you actually tried it?
    The other bigger issue is that the Win32_Terminal class will always return enabled on any server even if the terminal server is inaccessible and even if it is in Admin mode.  All Servers since 2003 have Terminal Server running by default but not in
    Terminal Server mode.
    PortQry to 3389 will tell us that the TS is alive and available.  Win32_Terminal will report enabled even if the service is stopped.
    Win32_Terminal is only useful to admins and PortQry can be used by anyone.
    The above PowerShell code can be run on any system instead of installing PortQry or other software.
    The original question was "Check RDP connection".  RDP is available on all systems since XP.  The Win32_Terminal class is only available on Server class machines and it does not check to see if the RDP connection is available.
    ¯\_(ツ)_/¯

  • Need help to find a good shell script to delete logs, tablespace check, etc

    Can you help me to find a good working shell script to run as a cron job to check tablesapce free space per thredhold and delete old trace files, .aud files, etc.
    Thanks,

    refer the links:-
    http://www.shutdownabort.com/dbaqueries/Structure_Tablespace.php
    http://gavinsoorma.com/unix-for-the-dba/
    Shell script to delete archive logs that are 10 days old.
    Re: How to delete archivelogs ???????
    http://kmit4u.blogspot.com/2010/10/shell-script-backup-oracle-database-by.html

  • I need AD Health status via Power Shell script

    Dear All,
    I need AD Health power shell script and it has to be sent via email as report on daily basis
    Can anyone help on this?
    Thanks,
    Pushparaj

    I found below script which can be used, but i would request run these scirpts in test environment before executing in production.
    http://fearthemonkey.co.uk/using-powershell-to-perform-dc-health-checks/
    http://www.wolffhaven45.com/blog/powershell/automate-some-active-directory-health-checks-via-powershell/
    You can also search for scripts in below repository.
    http://gallery.technet.microsoft.com/
    Also, for scripting related request, its better to post the thread in dedicated scripting/powershell forum.
    http://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=ITCG
    Awinish Vishwakarma - MVP
    My Blog: awinish.wordpress.com
    Disclaimer This posting is provided AS-IS with no warranties/guarantees and confers no rights.

  • Why execution status of stored procedure in shell script is returning same?

    Hi Friends,
    My shell script has below code to execute Pl/Sql procedure.depending on pl/sql procedure status i need to execute the script further.
    i am testing error condition.So i kept exe instead of exec for executing procedure.it suppose to return non zero.But iam not getting the correct status in shell script using $?.
    even for error condition also status is returning zero(0).How to catch execution status of stored procedure in shell script?
    can you please me suggest whats is wrong in below code?
    echo "*************************************************************"
    echo "             cleaning replica tables"
    echo "*************************************************************"
    sqlplus -s migrat/****@dotis01<<ENDOFSQL
    WHENEVER SQLERROR EXIT 1;
    exe PKG_OTU_HELPER.SP_CLEANUPREPLICA;
    Commit;
    exit;
    ENDOFSQL
    status=$?
    echo $status // showing 0 always.
    +if [ $status -ne 0 ]+
    then
    echo "issues in cleaning in replica tables"
    exit;
    fi
    +#Loading of data from flat files to migration tables using sqlldr programs+
    echo "*************************************************************"
    echo "      Loading of data from flat files to migration tables"
    echo "*************************************************************"
    sh /opt/finaclesoftware/UBS_10.4.02_AIX/AIX/DB/CRM/Oracle/OTU/Retail/ControlFiles/LoadData1.com
    Thanks,
    Venkat Vadlamudi

    The whenever sqlerror clause is a sqlplus command. When Oracle (that is, the sql engine of the pl/sql engine) raises and error in a sql statement, the whenever sqlerror command determines what happens.
    Exec is also a sqlplus command, exec <procedure> is shorthand for begin <procedure> end;, that is, it creates an anonymous block.
    Your misspelling of exec as exe is not an Oracle error, it is a sqlplus error. The command never actually gets to Oracle, so there has not been a sqlerror for whenever sqlerror to respons to.
    Consider, I do not have a procedure called p
    SQL> desc p
    ERROR:
    ORA-04043: object p does not existI try to call it with exe as in your code:
    SQL> exe p;
    SP2-0042: unknown command "exe p" - rest of line ignored.Note the error message is form sqlplus (SP2).
    But, if I call it correctly usinf exec:
    SQL> exec p;
    BEGIN p; END;
    ERROR at line 1:
    ORA-06550: line 1, column 7:
    PLS-00201: identifier 'P' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignorednow I have a sql error, and whenever sqlerror exit 1 would quit sqlplus with a return value of 1.
    John

  • Power Shell Script for Check Remote machinces are live or not

    I have required a Power Shell Script for Check multiple Remote machines are live or not.Please guide me

    This will do it.
    http://gallery.technet.microsoft.com/Ping-IP-Adress-Range-d90ce82d
    &#175;\_(ツ)_/&#175;

  • Shell script directed to one Dynamic Dashboard to monitor status of all DB

    Hi team,
    straight to scenario now..
    I have 15 databases to manage..i wrote shell scripts for monitoring each database status of ping,listener,vnc server, concurrent server, forms server, metric server, workflow, filesystem usage, alert-log etc..
    Now each and every time i will get 15 mails for one database each half n hour and it will get filled for sure if i get many alerts at single time...i thought of having a dashboard where my script output should display alerts on 3-D pie chart, bar chart etc..
    Imagine all databases statuses on one dashboard with colours displaying peaks and lows also the data gets dynamic changes every 30 mins.....
    charts will let me know to fix the issue easier..so next time i wont care how many mails reach me i will look up to dashboard and can observe what went wrong...
    please let me know any third party software available or self oracle or linux tools available.....
    hope anyone would give me suitable solution
    thanks
    dkoracle

    AFAIK Grid Control is completely free*, you just have to be careful to not go into the pages that require Management Pack licensing if you haven't purchased them for the DBs you're monitoring.
    Personally I have always used a combination of GC and shell script alerts. You don't want the GC environment to be your SPoF.
    *other than the associated server costs                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for