The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
CRON problem rrlog AIX 1 01-15-2008 02:22 PM
cron job problem mokkan SUN Solaris 4 12-22-2007 04:25 PM
CRON problem VooDooMan UNIX for Dummies Questions & Answers 4 07-07-2005 08:06 PM
Cron problem redlotus72 UNIX for Dummies Questions & Answers 3 06-17-2005 02:22 PM
Cron problem Sn33R Shell Programming and Scripting 12 10-23-2003 07:08 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-05-2009
mas1888 mas1888 is offline
Registered User
  
 

Join Date: May 2009
Posts: 2
Problem with Cron

Hi i am new here and have a quick question.

i am receiving ./project.sh: line 12: syntax error near unexpected token `newline'
./project.sh: line 12: `echo "`date +"%F %R"` `md5sum /etc/passwd`" >> '

error message
here is my script. could you please help!

#!/bin/bash
# PROGRAM: project.sh
# OBJECTIVE: Log changes
# AUTHOR:
# DATE: May 2009
#
MYDIR=$HOME/bin
MYLOGDIR=$MYDIR/logs
#
echo "`date +"%F %R"` `wc /etc/passwd`" >> $MYLOGDIR/checkpasswd_wc.txt
#
echo "`date +"%F %R"` `md5sum /etc/passwd`" >> $MYLOGDIR/checkpasswd_md5.txt
#
echo " " >> $MYLOGDIR/passwd_file.txt
echo `date +"%F %R"` >> $MYLOGDIR/passwd_file.txt
more /etc/passwd >> $MYLOGDIR/passwd_file.txt
echo " " >> $MYLOGDIR/passwd_file.txt
echo " " >> $MYLOGDIR/passwd_file.txt
#
echo "`date +"%F %R"` `df -v |grep /home2`" >> $MYLOGDIR/check_ds.txt
#
echo " " >> $MYLOGDIR/checkds_all.txt
echo "`date +"%F %R"`" >> $MYLOGDIR/checkds_all.txt
df -v >> $MYLOGDIR/checkds_all.txt
echo " " >> $MYLOGDIR/checkds_all.txt
echo " " >> $MYLOGDIR/checkds_all.txt
#
#
  #2 (permalink)  
Old 05-05-2009
TonyFullerMalv's Avatar
TonyFullerMalv TonyFullerMalv is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Location: Malvern, Worcs. U.K.
Posts: 748
I can't see why cron is objecting but I would capture the date in a variable and then use the string where the script is currently calling date(1) to make the lines less complicated and only call date(1) once, e.g.:

Code:
DATESTR=`date +"%F %R"`
#
echo "${DATESTR} `wc /etc/passwd`" >> $MYLOGDIR/checkpasswd_wc.txt
#
echo "${DATESTR} `md5sum /etc/passwd`" >> $MYLOGDIR/checkpasswd_md5.txt

This also avoids nested speech marks which can cause grief.

HTH
  #3 (permalink)  
Old 05-05-2009
mas1888 mas1888 is offline
Registered User
  
 

Join Date: May 2009
Posts: 2
that worked thanks. just made a variable for the date and switched it out and it worked. Thanks for the help!
  #4 (permalink)  
Old 05-06-2009
thegeek thegeek is offline
Registered User
  
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 464
Even though am not able to find out how you are calling this bash script.

I could able to realize that, when you use the % in the crontab it will be taken as newline, you can find more info by googling as percentage + cron - Google Search...

from a comment in Andrew Beacock's Blog: Having cron troubles with percent (%) signs in crontabs?


Code:
Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.

  #5 (permalink)  
Old 05-06-2009
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,184
You can't nest double quotes. This caused the syntax error.

Quote:
echo "`date +"%F %R"` `wc /etc/passwd`" >> $MYLOGDIR/checkpasswd_wc.txt

Code:
echo "`date +'%F %R'` `wc /etc/passwd`" >>$MYLOGDIR/checkpasswd_wc.txt

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:12 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0