LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Reminder Command (https://www.linuxquestions.org/questions/programming-9/reminder-command-4175427975/)

Salem 09-19-2012 07:17 AM

Reminder Command
 
Hello everyone,

I have something wrong with this command
i don,t know what is the problem
can someone help me please :study:

Code:

! /bin/sh
Start your code from here
!/bin/bash
Define Files and dates
EventMemberFile="./Event-member.data"
ReminderFile="./Reminder.email"
currentMonth=`date +"%m"`
currentDay=`date +"%d"`

read the event member files line by line
OLDIFS=$IFS
IFS=','
while read EventTitle FirstName LastName MeetingMonth MeetingDay EmailAddress
do
avoid comments
[[ "$EventTitle" = \#* ]] && continue
compare dates change parameters and send emails

if [[ "$MeetingMonth" == "$currentMonth" ]] ; 
  then
        sed -e 's/__FULLNAME__/'$FirstName' '$LastName'/g' -e 's/__Project__/'$EventTitle'/g' $ReminderFile


        #sed -e 's/__FULLNAME__/'$FirstName' '$LastName'/g' -e 's/__Project__/'$EventTitle'/g' $ReminderFile | mail -s "meeting reminder""alzaabi.slm@gmail.com"

else echo "Ignoring" $EventTitle "because it's not today" ;
fi
echo $EventTitle $FirstName $LastName $MeetingMonth $MeetingDay $EmailAddress



done < $EventMemberFile

IFS=$OLDIFS
exit 0


cortman 09-19-2012 07:30 AM

You didn't quote out your comments, for one-

Code:

# Start your code from here

pixellany 09-19-2012 07:45 AM

A script typically starts with something like this---to tell the shell what to use to run the script:
#!/bin/bash

Also, you need to format your code for readability (by us---and by YOU)---example:
Code:

while read <stuff>; do
    if <something>; then
          <do stuff>
    else
          <do different stuff>
    fi
    <more stuff>
done

finally, I'm not sure this is legal:
Code:

while read EventTitle FirstName LastName MeetingMonth MeetingDay EmailAddress
What is the intent here?

pixellany 09-19-2012 07:51 AM

PS---Tell us exactly what happens when you run the script. Just saying "something is wrong" does not give us any clues.

Salem 09-19-2012 01:04 PM

Quote:

Originally Posted by pixellany (Post 4784102)
PS---Tell us exactly what happens when you run the script. Just saying "something is wrong" does not give us any clues.

thank you for your reply

this is the error
Code:

./MeetingReminder.sh: line 3: !/bin/bash: No such file or directory
./MeetingReminder.sh: line 4: Define: command not found


Habitual 09-19-2012 01:14 PM

terminal >
Code:

which $SHELL
output please.

cortman 09-20-2012 09:02 AM

Quote:

Originally Posted by Salem (Post 4784349)
thank you for your reply

this is the error
Code:

./MeetingReminder.sh: line 3: !/bin/bash: No such file or directory
./MeetingReminder.sh: line 4: Define: command not found


You need to put a hash mark # in front of !/bin/sh:

Code:

#!/bin/sh
And you need hash marks in front of anything that isn't code, just as I said earlier.

suicidaleggroll 09-20-2012 12:28 PM

Are you trying to run this with sh or bash?

You have "! /bin/sh" at the top, which while it's the wrong syntax, implies you want to run the script in sh, then two lines later you have "!/bin/bash", which again is the wrong syntax, but implies you want to run the script in bash. Pick one, change it to #!/bin/sh or #!/bin/bash, delete the other, and put a # in front of all comment lines.

David the H. 09-23-2012 04:48 AM

I highly suggest that the OP sit down with a good scripting tutorial and start working through it. Don't try writing complex scripts until you're at least reasonably familiar with the basics of the syntax.

It also goes without saying that you shouldn't just cut&paste code from the net without understanding what it does.


I recommend the BashGuide and linuxcommand as good starting points. Also have a look at the other links below for commonly-made errors and situational how-tos.

http://mywiki.wooledge.org/BashGuide
http://www.linuxcommand.org/index.php

http://mywiki.wooledge.org/BashPitfalls
http://wiki.bash-hackers.org/scripting/newbie_traps
http://mywiki.wooledge.org/BashFAQ


Quote:

Originally Posted by pixellany (Post 4784096)
finally, I'm not sure this is legal:
Code:

while read EventTitle FirstName LastName MeetingMonth MeetingDay EmailAddress
What is the intent here?

For the record, this is perfectly legal syntax. read will store one word from the input line (as defined by IFS) in each variable supplied to it, with any additional text going into the final one.

You could also similarly use the -a option (assuming bash or similar); only then the words are stored in an array instead.

David the H. 09-23-2012 05:03 AM

By the way, there are already many good "reminder" style programs out there. Is there any special reason why you want to script this?

konsolebox 09-23-2012 05:42 AM

Reminds of the Slackware quotes. If you could place reminders instead..
I don't have Slackware yet though so I can't examine. It probably has something to do with the post-login scripts in bash.


All times are GMT -5. The time now is 10:07 PM.