Maybe something more like:
Note, however, that this (and your earlier code) will probably not do what you want on January 1st each year.
Note also, that if you were calling date twice to assign values to year and doy (or any other two time/date values), that is dangerous. If the script is run close to midnight, there is always a chance that two or more invocations of date will be run on different days (or months, or even years). Without knowing how this string will be used and when your script will be invoked, it is hard to guess at whether or not this will be a problem in your environment.
But, getting the year and Julian day together does get rid of your problem with leading zeros being stripped by the decrement. If you don't want to use printf and you're dealing with non-negative integral values, you could also use typeset to specify that expansions of a given variable are to be right justified with zero fill to a given number of digits. For example, with ksh, the sequence of commands:
produces the output:
This User Gave Thanks to Don Cragun For This Post:
Hello i am having an issue with bash script and this is the code
now=$(cat hosts1.txt | awk '{print $2;}')
while read n ;do
ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers'
When i execute only part with cat, it... (8 Replies)
Hi everyone
I have a problem with my script
If I try directly this command
/usr/bin/nice -n 19 mysqldump -u root --password="******" wiki_schneider -c | nice -n 19 gzip -9 > /point_de_montage/$(date '+%Y%m%d')-wiki-db.sql.gz
It works
But if I simply add this command in a script and... (8 Replies)
Hi All,
I am trying to select 30 days older files under current directory ,but not from subdirectory using below command.
find <Dir> -type f -mtime + 30
This command selecting all the files from current directory and also from sub directory .
I read some documention through internet ,... (1 Reply)
Hello.
I would like to ask your help regarding the cp command. We are using a cp command to create a back-up copy of our file but to no avail. It's just not working. We already checked the file and directory permissions and all seems correct.
We have a script (ftp.script) which calls on... (1 Reply)
Hi everyone,
when executing this command in unix:
echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error.
here is content of my script:
tdbsrvr$ vi hc.sh
"hc.sh" 22 lines, 509... (4 Replies)
I have three files a.txt , b.txt , c.txt in a directory called my_dir1 .These files were created before two or three months . I have a tar file called my_tar1.tar which contains three files a.txt , b.txt , d.txt . Somebody untarred the my_tar1.tar into my_dir1 directory. So existing two files were... (1 Reply)
Hi Guys,
I have about 12000 files in a folder and I want to copy these to another folder. I am using the cp command to do this but it errors out saying cp -- argument list too long.
Is there any way to get around this?
I don't want to do a mv but use only cp.
Thanks (9 Replies)
Hi,
I have installed opensolaris 10 in VMware. Everything is fine except ls command is not working. It is not displaying any files and directories. Sorry if the question is soo trivial. (8 Replies)
I have a Solaris 8 Ultra 1 on my network that we use as a utility server.
The last command, which looks in the /var/adm/wtmpx file, is not working.
When I do a last, the latest entry is dated June 3, but the /var/adm/wtmpx file is dated whenever a login is successful (verified by typing a... (3 Replies)