script with mail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script with mail
# 8  
Old 08-05-2012
First, remove the single quotes around the occurrences of $a.
Second, what shell are you using? Depending on this, you may be able to use shell arithmetic expressions, like a=$((a+1)) in bash, otherwise you will need to take a different approach, sth. like expr that donadarsh mentioned.
# 9  
Old 08-05-2012
my mistake - '$a' shouldn't be in single quote. It will read it as one string. better use "$a".
# 10  
Old 08-05-2012
Quote:
Originally Posted by donadarsh
my mistake - '$a' shouldn't be in single quote. It will read it as one string. better use "$a".
Code:
#!/bin/bash

limite=3
a=0

while ["$a" -le "3"];
do


if ["$a" -eq "1"];
then

pru=/usr/bin/mei.txt
cat $pru | mail -s "IMEIS" mathias@wirtel.com.ar

fi




if ["$a" -eq "2"];
then

pru=/usr/bin/mei2.txt
cat $pru | mail -s "IMEIS" mathias@wirtel.com.ar

fi


a=$a+1

done


if ["$a" -eq "2"];
then

a=1

fi



the code with " but return me this
Code:
/usr/bin/imei: line 6: [0: command not found
/usr/bin/imei: line 35: [0: command not found


Last edited by Franklin52; 08-06-2012 at 03:48 AM.. Reason: Please use code tags for data and code samples
# 11  
Old 08-06-2012
Debian

Code:
#!/bin/bash

limite=3
a=0

while [ "$a" -le 3 ]; do

    if [ "$a" -eq 1 ]; then
        pru=/usr/bin/mei.txt
        cat $pru | mail -s "IMEIS" mathias@wirtel.com.ar
    fi

    if [ "$a" -eq 2 ]; then
        pru=/usr/bin/mei2.txt
        cat $pru | mail -s "IMEIS" mathias@wirtel.com.ar
    fi

    #a=$a+1
    a=`expr $a + 1`

done

if [ "$a" -eq 2 ]; then
    a=1
fi

# 12  
Old 08-06-2012
Hi,

1. remove all semi-colons they are not required in shell scripts
2. remove the single quotes around the varaibles in if conditon
i.e.
Code:
 
while [ $a -le $limite ]

the single quotes disable varaible interpolation, to use the value of the variable either use
Code:
""

double quotes or don't use quotes at all
3.
Code:
$a=$a+1

is wrong
you can write this section as
Code:
let a=a+1

(notice no spaces between
Code:
a=a+1

)
or
Code:
a=`expr $a + 1`

(notice the spaces and backticks this time)
# 13  
Old 08-06-2012
[ is command and need arguments and argument delimiters, it is not bracket like in the programming languages.
if variable is empty, then you get error if value is empty. In that case double quotes => you have always argumen even it's empty.
$a is not same as "$a" in the command line if value of the a is empty.
Code:
#!/bin/bash

limite=3
a=1

while [  "$a"  -le  "$limite"  ]   # this is okay, no problem
# or while (( a <= limite ))
do

if  [  "$a"  -eq 1 ]   # delimiters after command [ and between arguments 
# or if  (( a == 1 ))
then
    pru=/usr/bin/mei.txt
    cat $pru | mail -s "IMEIS" account@domain.com
fi

if  [ "$a"  -eq  2 ]
# or  if (( a == 2 ))
then
    pru=/usr/bin/mei2.txt
   cat $pru | mail -s "IMEIS" account@domain.com
fi
  
#$a=$a+1
((a=a+1))   # works fine in ksh and bash, but not in dash
a=$((a+1)) # posix compatible version
# or use let command, it's also builtin command, expr does not

done

if [ "$a" -eq 2 ]
# or if (( a == 2 ))
then
   a=1
fi

# 14  
Old 08-06-2012
Quote:
Originally Posted by kshji
[ is command and need arguments and argument delimiters, it is not bracket like in the programming languages.
if variable is empty, then you get error if value is empty. In that case double quotes => you have always argumen even it's empty.
$a is not same as "$a" in the command line if value of the a is empty.
Code:
#!/bin/bash

limite=3
a=1

while [  "$a"  -le  "$limite"  ]   # this is okay, no problem
# or while (( a <= limite ))
do

if  [  "$a"  -eq 1 ]   # delimiters after command [ and between arguments 
# or if  (( a == 1 ))
then
    pru=/usr/bin/mei.txt
    cat $pru | mail -s "IMEIS" account@domain.com
fi

if  [ "$a"  -eq  2 ]
# or  if (( a == 2 ))
then
    pru=/usr/bin/mei2.txt
   cat $pru | mail -s "IMEIS" account@domain.com
fi
  
#$a=$a+1
((a=a+1))   # works fine in ksh and bash, but not in dash
a=$((a+1)) # posix compatible version
# or use let command, it's also builtin command, expr does not

done

if [ "$a" -eq 2 ]
# or if (( a == 2 ))
then
   a=1
fi




thank you very much but , i have a problem

the code now is

Code:
#!/bin/bash

limite=2
a=1

while [  "$a"  -le  "$limite"  ];   # this is okay, no problem

do

if  [  "$a"  -eq "1" ];   

then
    pru=/usr/bin/mei.txt
    cat $pru | mail -s "IMEIS" account@domain.com
fi

if  [ "$a"  -eq  "2" ];

then
    pru=/usr/bin/mei2.txt
   cat $pru | mail -s "IMEIS" account@domain.com
fi


a=$((a+1)) # posix compatible version


done

if [ "$a" -eq "2" ];

then
   a=1
fi


they not have sintax error but , the send me 2 mails , the if not found , i dont know really why.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Client was not authenticated to send anonymous mail during MAIL FROM (in reply to MAIL FROM comm

I am having trouble getting mail to work on a red hat server. At first I was getting this message. Diagnostic-Code: X-Postfix; delivery temporarily suspended: connect to :25: Connection refused Then added the port to my firewall. Then I temporarily turned off selinux. I then copied this file... (1 Reply)
Discussion started by: cokedude
1 Replies

2. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

3. Shell Programming and Scripting

Mail script

Hi Folks Please help me on the below script I want to write a script to mail with the subject as "xxxxx" on (lastday-1)_month_year. means for this month the subject is like "xxxx" on 30_jan_2013 for february the subject is like "xxxx" on 27_feb_2013 only the subject needs to change,... (3 Replies)
Discussion started by: coolboy98699
3 Replies

4. Shell Programming and Scripting

mail script

Hi.. I need to create a script which will send a mail with attached file of log whenever its invoked with some text in its body. (Using Sendmail) I don't have any idea regarding that. any one help me out with this. Thanks, (1 Reply)
Discussion started by: sukhdip
1 Replies

5. UNIX for Advanced & Expert Users

need to configure mail setting to send mail to outlook mail server

i have sun machines having solaris 9 & 10 OS . Now i need to send mail from the machines to my outlook account . I have the ip adress of OUTLOOK mail server. Now what are the setting i need to do in solaris machines so that i can use mailx or sendmail. actually i am trying to automate the high... (2 Replies)
Discussion started by: amitranjansahu
2 Replies

6. Shell Programming and Scripting

script to read mail on a mail server

Hi All, Is there any way Unix shell script can directly read a mail on a mail server (for eg. abc@xyz.com) and save it as a text file in a unix directory ? Thanks PRKS ---------- Post updated at 08:37 AM ---------- Previous update was at 08:36 AM ---------- I am using ksh (1 Reply)
Discussion started by: PRKS
1 Replies

7. Solaris

how to forward mail in /var/mail/username to external mail

Dear All, Now I use solaris 10 and I try to forward mail from /var/mail/username to their external mail so what should I do? thank u in advance (2 Replies)
Discussion started by: unitipon
2 Replies

8. UNIX for Dummies Questions & Answers

Mail Script need Help???

Hi I have written the folowing mail function: SENDMAIL () { mailx -r 'Team' -s ' QA Test & Work Build & Deployment ---> STARTED' $INTERESTED<<EOF Maintenance is going on $path in 10 Minutes. So Please exit the Accounts EOF return } Above is working fine for me.. The... (2 Replies)
Discussion started by: gkrishnag
2 Replies

9. Shell Programming and Scripting

I need a script that script extract info from mail

Hello, I receive email once an hour that looks like: subject line: dialin body: ip address ip address . . sometimes the body has no ip address in it(blank mail) I want a script that will send to my email every 12 hours the ip numbers and the time and data something like: data,... (1 Reply)
Discussion started by: meravd
1 Replies

10. Shell Programming and Scripting

e-mail script

Hi there, Just wondering if anyone can help me with a unix script that will allow to check if a file is in a directory and if it is then e-mail it to someone and then move the file to another directory. I have come up with nothing right now and was hoping someone could get the ball rolling... (1 Reply)
Discussion started by: ben_shark
1 Replies
Login or Register to Ask a Question