3 thoughts on “Introduction to Linux Shell Scripting

  1. hi i need one help. kindly help me in writing small schell script.
    i have one file which contains,
    define service{
    use system-disk-wmware
    host_name1 suresh
    host_name SJPVMW03
    service_description SYSTEM-DISK-SJP_DELL_EQLOGIC_ISCSI_Tier1_Vol5
    contact_groups GMC,TICKET-NO-RECOVERY,SJP_VMWARE_SERVERS,GBS_Infra_Windows_Support_L1,WW_FlexVirtual_Admin
    check_command fs_vmfs_vmware!”/vmfs/volumes/SJP_DELL_EQLOGIC_ISCSI_Tier1_Vol5″!90!95
    _WARNINGTHRESHOLD Disk usage is above 90%
    _CRITICALTHRESHOLD Disk usage if above 95%
    _RESOLUTIONTEAM GBS Infra Windows Support L1
    }

    define service{
    use vmware-cpu
    host_name TPIVMW02
    service_description VMW_CPU
    contact_groups GMC,TICKET-NO-RECOVERY,TPI_Infra_Server,WW_FlexVirtual_Admin,GBS_Infra_Windows_Support_L1
    check_command fs_cpu_vmware!90!95
    _CRITICALSEVERITY 2
    host_number 5
    _RESOLUTIONTEAM GBS Infra Windows Support L1
    }

    define service{
    use system-disk-generic
    host_name HKDUD323
    service_description SYSTEM-DISK-/usr
    contact_groups Global_Infra_Unix_Support_-_L2,GMC,TICKET-RECOVERY
    check_command fs_disk_utilization!/usr!10!5
    _CRITICALSEVERITY 3
    _WARNINGTHRESHOLD <10%
    _CRITICALTHRESHOLD infile
    {
    awk -F: ‘BEGIN{ sl=”use”}
    $1~sl && head == 1 { head=0; exit 0}
    $1~sl && head == 0 { head=1; }
    head == 1 {
    gsub(/^[ \t]+/,””,$1); # remove leading spaces
    gsub(/[ \t]+$/,””,$1); # remove trailing spaces
    gsub(/[ \t]+$/,””,$1);
    printf( “%s\t”, $1)
    }
    ‘ infile
    #echo
    awk -F: ‘BEGIN { sl=”use”}
    $1~sl { printf( “%s\n”, “”) }
    {
    gsub(/^[ \t]+/,” “,$2); # remove leading spaces
    gsub(/[ \t]+$/,” “,$2); # remove trailing spaces
    printf( “%s\t”,$2);
    }
    ‘ infile
    echo
    } | column -t -s “$(printf ‘%b’ ‘\t’)”

    if run the output
    # ./test.sh myfile.csv ‘host_name|use’

    use host_name1 host_name
    system-disk-wmware suresh SJPVMW03
    vmware-cpu TPIVMW02
    system-disk-generic HKDUD323
    if the above output, host_name colums is printing in host_name1
    but i need to print,
    use host_name1 host_name
    system-disk-wmware suresh SJPVMW03
    vmware-cpu N/A TPIVMW02
    system-disk-generic N/A HKDUD323

    if string not found in a line within a define services means, it should print N/A in that column

  2. #!/bin/ksh
    read cikey
    echo $cikey>output.txt
    h1=`cut -d: -f1 output.txt`
    u1=`cut -d: -f2 output.txt`
    d1=`cut -d: -f3 output.txt`
    con $h1 </dev/null
    su – $u1 </dev/null
    db2 list active databases
    db2 connect to $d1
    db2 list tablespaces show detail|grep -i state
    db2 terminate

    p1=`cat /etc/services|grep -i ^$u1|grep -o [0-9][0-9][0-9][0-9][0-9]`
    echo $p1

    exit
    EOF1
    EOF

  3. i am trying to assign output of filter to p1 but when i ran the script shell script is not showing any output.please let me know what is the mistake

Leave a Reply

Your email address will not be published. Required fields are marked *