help me bash scripts

Discussion in 'Programming/Scripts' started by hudipirlo, Apr 16, 2009.

  1. hudipirlo

    hudipirlo New Member

    dear all master

    i am newbie in linux scripting

    I want to make a script

    example:

    #!/bin/bash
    # scripts for log import

    ls -al /home2/import/`date +%Y%m%d`/* > /home/tplinux/in/`date +%Y%m%d`.txt
    sleep 2
    temp=$(cat /home/tplinux/in/`date +%Y%m%d`.txt | wc -l /home/tplinux/in/`date +%Y%m%d`.txt )
    echo $temp

    #function to send mail with subject "FAIL"
    func_mail_fail () {
    echo $temp | mail -s "'WARNING'report import server `hostname`-HERO SPM GATOT `date +%d-%m-%Y`" mailto:[email protected]
    }

    #function to send mail with subject "Good"
    func_mail_good () {
    echo $temp | mail -s "report import server `hostname`-HERO SPM GATOT `date +%d-%m-%Y`" mailto:[email protected]
    }

    #testing the send log from Server
    ((temp>20)) && func_mail_fail || func_mail_good


    with the logic of each number of lines that are less than 20 will send a warning email

    note: the above scripts still fail

    please tell the solution to my email [email protected]

    thanks for your help



    bahudin
     
  2. vernond

    vernond New Member

    Try executing the commands one by one from the command line so that you can see exactly where and why the script is failing.

    If the commands don't work manually then they're not going to work in a script.

    Copy the error messages and allow google to help you find solutions. It's a lot of fun learning this way, because there are normally many different solutions and you will learn PLENTY about shell scripting and your OS.
     
  3. tebokkel

    tebokkel New Member

    The way you test 'temp' is wrong. It's not a test (you should use [] for that, see 'man test'), and it's not a variable.

    [ $temp -gt 20 ] && fail || good

    Tip: execute your script with "bash -x scriptname" and you'll see every command executed (or change the first line to include -x).

    Paul
     

Share This Page