LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 03-15-2006, 06:53 PM   #1
Pyrate_02
LQ Newbie
 
Registered: Mar 2006
Location: Salem, OR
Distribution: Mandriva
Posts: 9

Rep: Reputation: 0
Thumbs up Date & time as dir name


I am trying to write a shell script that will creat a directory with the current date and time as name (mkdir /home/??), then move some files into it (mv /home/cam/*.avi /home/??). This is for a security cam setup, using lavrec as the recorder. Any sugestions for syntax?
 
Old 03-15-2006, 06:57 PM   #2
ckoniecny
Member
 
Registered: Oct 2005
Posts: 162

Rep: Reputation: 30
The command you will want to execute at the prompt to get the date and time is:
Code:
$ date +%m-%d-%Y-%H:%M
That will output
Code:
3-15-2006-20:11
In your case, you will want to do

Code:
#!/bin/zsh

CUR_DATE=`date +%m-%d-%Y-%H:%D`


if [ -d /home/$CUR_DATE ];
then
     cp /home/cam/*.avi /home/$CUR_DATE
else
     mkdir $CUR_DATE
fi

Last edited by ckoniecny; 03-15-2006 at 07:11 PM.
 
Old 03-16-2006, 01:24 AM   #3
Pyrate_02
LQ Newbie
 
Registered: Mar 2006
Location: Salem, OR
Distribution: Mandriva
Posts: 9

Original Poster
Rep: Reputation: 0
Wink Well; Almost

Tried that code verbatum. Got zip. Played with it for awhile, and finally got to:

cd /home/cam

CUR_DATE='date +%m%d-%Y-%H:%D'

mkdir $CUR_DATE

mv /home/cam/*.avi /home/cam/$CUR_DATE

which got me a directory called "+%m%d-%Y-%H:%D", with a directory called "date" in it, along with all of the avis. It's close, but is not reading the format.
I'm using bash in Mandriva. Any chance that's my problem?
 
Old 03-16-2006, 05:43 AM   #4
ckoniecny
Member
 
Registered: Oct 2005
Posts: 162

Rep: Reputation: 30
Notice that CUR_DATE=`date +%m-%d-%Y-%H:%D` is not encapsulated with aposterphies, it uses the character that is next to the number one on the keyboard. This tells the script to execute the command "date". Copy and paste my script, you will see that it does work.
 
Old 03-16-2006, 01:21 PM   #5
Pyrate_02
LQ Newbie
 
Registered: Mar 2006
Location: Salem, OR
Distribution: Mandriva
Posts: 9

Original Poster
Rep: Reputation: 0
Yer rite! It works now.
That's what happens when you get old. You can't see. Increased my font size and saw what you told me. I beat my head against the wall for 3 days on that one.
Thank you very much for your help.
 
Old 03-17-2006, 02:40 AM   #6
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
If you don't want to use backquotes, try using the out=$(command) syntax instead.

Note also that you can play around with the format of the dates by changing the date command appropriately.
 
Old 03-18-2006, 03:53 AM   #7
Pyrate_02
LQ Newbie
 
Registered: Mar 2006
Location: Salem, OR
Distribution: Mandriva
Posts: 9

Original Poster
Rep: Reputation: 0
Thumbs up Date & time as dir name

Did that. Got the format the way I wanted it, then added a tar/zip line. Thing works smooth as a baby's bum. That's why I love Linux so much. Get stuck on something, and people trip over themselves to help you. Where else in the world do you see that attitude?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help With Date & Time Jude Lucien Linux - General 3 10-11-2005 02:46 PM
Newbie Help With Date & Time Jude Lucien Debian 2 10-11-2005 10:21 AM
Start Date + Time Duration = End Date/Time calculator? ToBe Linux - General 3 09-26-2005 10:17 AM
Problem with date & time kosmonaft Linux - General 3 08-17-2005 11:23 AM
Time & Date setting not sticking nathanv117 Linux - Newbie 3 04-10-2005 09:05 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration