LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 03-03-2008, 11:45 AM   #1
jimmyjiang
Member
 
Registered: Jun 2006
Posts: 132

Rep: Reputation: 15
date value space prolbem


hi,
my small bash script has a problem, when the date is 10-31, it runs fine, but when it is 1-9 it get problems.

#!/bin/sh
#take the current time's hour value -1, then grep with "Feb 12 13" format.
vH=`date +"%H"`
echo $vH

vD=`date +"%e"`
echo $vD
echo "$vD"

vM=`date +"%b"`
echo $vM

v5="$vM $vD $vH"
echo $v5

#create backup folder by date, only need when you need backup hourly maillog file.
if [ ! -e /home/oiprod/$vD ]
then
mkdir /home/oiprod/$vD
fi

cp -p /home/oiprod/smtp_mail_log/maillog /home/oiprod/$vD/maillog${vH}

here is the error message:
[oiprod@admin1 oiprod]$ ./maillog2.sh
12
3
3
Mar
Mar 3 12
./maillog2.sh: [: /home/oiprod/: binary operator expected
cp: copying multiple files, but last argument `3/maillog12' is not a directory
Try `cp --help' for more information.

anyone knowns why?
thanks!
jimmy
 
Old 03-04-2008, 09:56 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by jimmyjiang View Post
anyone knowns why?
Code:
date '+%e'
does space padding. To get no padding, use
Code:
date '+%-d'
 
Old 03-04-2008, 10:00 PM   #3
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Btw, this
Quote:
Originally Posted by jimmyjiang View Post
Code:
if [ ! -e /home/oiprod/$vD ]
then
mkdir /home/oiprod/$vD
fi
is equivalent to this:
Code:
mkdir -p /home/oiprod/$vD
 
Old 03-05-2008, 12:24 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Id also amend
/home/oiprod/$vD/maillog${vH}
to
/home/oiprod/${vD}/maillog${vH}

and check the create was ok ie similar to
Code:
mkdir -p /home/oiprod/${vD}
if [[ $? -eq 0 ]]
then
    do cp
else
    echo "error"
    exit 1
fi
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting system date and time affecting the clock and date on BIOS satimis Ubuntu 7 09-21-2007 08:02 AM
what is the correct syntax order for tar with --after-date DATE, --newer DAT farhan Linux - General 1 03-16-2007 08:43 AM
Two hard drives - two OS's - one big bootloader prolbem epsilon72 Linux - General 5 03-13-2007 11:16 AM
FC3 : KPPP DNS resolve prolbem sandgroper Fedora 4 07-14-2006 12:05 AM
prolbem configuration sendmail? shams Fedora 11 06-22-2006 11:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration