#16
  1. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    Does it REALLY have to be in csh?
    Someone more familiar in the shell scripting language would need to step in - it's been 15 or so years since I even tried to write a csh script and I hated it then!
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  2. #17
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    26
    Rep Power
    0
    hi SimonJM,
    It compulsary to me write in C shell.
    I only need this part be write in C shell,because other part i already translate to C shell.
    Code:
    email=$(grep "^$3" $folder/config_2.txt | awk '{print $2'})
    Hopefully,u can help me?
  4. #18
  5. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    Ok, let's see what we can contrive after a visit to man csh:

    Code:
    set email = `grep "^$3" $folder/config_2.txt | awk '{print $2'}`
    From what I recall, the spaces around the = are needed.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  6. #19
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    26
    Rep Power
    0
    hi SimonJM,
    Thx very much is working. Can u help me 1 more time. This is complete code that i translate it to Csh. And the output i send to my email. However i got problem with the email i receive for my output:
    Code:
    #!/bin/csh
    set app_dir = "/ebsxe/ebs25/users/mmlim/assignment01"
    set line_array = (`cat $app_dir/config_path`)
    set SUBJECT = "EBSASIN Loader possible down"
    set line = "$app_dir/log_file"
    set line2 = "$app_dir/log_file2"
    
    @ index1 = 1
    @ index2 = 2
    @ index3 = 3
    
    while ( $index1 && $index2 && $index3 <= $#line_array )
    
            set dir = $line_array[$index1]
            set limit = $line_array[$index2]
            set class = $line_array[$index3]
    
            set email = ( `grep "^$class" $app_dir/config_recipient | awk '{print $2}' ` )
    
            cd $dir
            set filecount = ( `ls -1 | wc -l` )
    
            if ( $filecount <= $limit ) then
                     echo " hello  " >> ${line}
                     mailx -s "${SUBJECT}" "${email}" < ${line}
            else
                     echo " overload " >> ${line2}
                     mailx -s "${SUBJECT}" "${email}" < ${line2}
            endif
    
            @ index1 += 3
            @ index2 += 3
            @ index3 += 3
    
    end
    \rm -f ${line}
    \rm -f ${line2}
    This command is working and can sent the output to my email. However, i receive 4 email is like this:
    1st email:
    Hello
    2nd email :
    Hello
    Hello
    3rd email :
    overload
    4rd email :
    overload
    overload
    but i just want it sent 2 email like this 1:
    1st email:
    Hello
    Hello
    2nd email :
    overload
    overload
    The flow of this script same like korn shell script before this.
  8. #20
  9. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    You are sending a mail each time around the loop. If you want just two emails (one for each case) with all the information in them, you will need to store the data away on an ongoing basis and just issue the emails when all the processing is completed.
    The first part of that you are already doing with the:
    Code:
    echo " hello  " >> ${line}
    and
    Code:
    echo " overload " >> ${line2}
    lines. Keep those, but move the mailx commands you have to the bototm of the script (just after the end command) and that should do it.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  10. #21
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    26
    Rep Power
    0
    hi SimonJM,
    Ya...that 1 of the method.
    But if me put this command after when ....end command, $email is not function able.
    Code:
    mailx -s "${SUBJECT}" "${email}" < ${line}
  12. #22
  13. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    Ok, the question becomes - who do you wish to email with what subject and content?
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  14. #23
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    26
    Rep Power
    0
    hi SimonJM,
    I already find the way to overcome that problem. Thank for you help.
    How can i find u next time beside in this forum?
  16. #24
  17. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    I look in here fairly often, so this is probably the best place to rack me down!

    Glad you got it all sorted out, even if I am not convinced you need to do it in csh!
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  18. #25
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    26
    Rep Power
    0
    Hi SimonJM,
    For this code last time u mention :
    Code:
    #!/bin/ksh
    folder="/ebsxe/ebs25/users/mmlim/assignment01/dir01"
    cd $folder
    
    while read file
    do
       set $(echo ${file})
       cd $1
       var=$(ls -1 | wc -l)
       email=$(grep "^$3" $folder/config_2.txt | awk ' {print $2})
       if [[ $var -le $2 ]]
       then
          echo "  $email "
       else
          echo " $email "
       fi
    done <config.txt
    I try to run in ksh ,i found that it not function .I think it because of this statement :
    [/CODE]
    email=$(grep "^$3" $folder/config_2.txt | awk ' {print $2})
    [CODE]
  20. #26
  21. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    Gah, I missed out some punctuation (closing apostrophe for the awk) - sorry about that!

    Code:
    email=$(grep "^$3" $folder/config_2.txt | awk '{print $2}')
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  22. #27
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    26
    Rep Power
    0
    Hi SimonJM,
    Erm..i still same....not error come out.but not have output also..
  24. #28
  25. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    Is this back using csh?

    If so:
    Code:
    email=`grep "^$3" $folder/config_2.txt | awk '{print $2}'`
    Which is changing the $( ... ) to ` ... `
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  26. #29
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    26
    Rep Power
    0
    Hi ,
    I try already in korn but also not effective.

    I got another problem .Since this code :
    Code:
    email=`grep "^$3" $folder/config_2.txt | awk '{print $2}'`
    Its only print $2. If i add more than 1 email in each group like this
    Code:
    config_2.txt
    group1 jason@gmail.com allan@gmail.com baby@gmail.com
    group2 allan@gmail.com baby@gmail.com
    group3 baby@gmail.com
    group4 justin@gmail.com
    But i want the script to read all variable $2 ,$3 and $4 by itself and not need to set like awk'{print $2 $3 $4}'
  28. #30
  29. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    Ahh ok, now we will need to drop awk and call on the powers of cut!

    Code:
    email=`grep "^$3" $folder/config_2.txt | cut -d " " -f 2-`
    Now what we are doing is using cut to pass on field 2 (-f 2-) onwards, where the fields are separated by spaces (-d " ").
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo