LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 03-23-2006, 12:44 PM   #1
smudge|lala
Member
 
Registered: Jan 2004
Location: New Zealand
Distribution: Mint | Sabayon
Posts: 160

Rep: Reputation: 16
BASH commands include timestamp in filename


Admin - Is it worth having a seperate forum dedicated to Bash?

I have been experimenting with the import command, importing xwindows.

One of the side affects is the numbering sequence as cycling them with imagemagick does not play in order as images start off with 1.miff, 2.miff all the way to infinity.miff and not specifying the number format say 0001.miff, 0002.miff means they animate in random sequence. I can rename them afterwards, but would be nice to do it all on the fly.

I thought about trying to force a number sequence OR include the system timestamp into the filename, so 0156489458.miff 0156489462.miff 0156489466.miff and so on, whatever the system reported. This way I can interpolate the image times for accuracy.

I have hunted Linux Commands and ss64 but cannot find any reference or dedicated command for timestamp. I may be outreaching what I need to do, when really specifying the name type, say a million 0000000.miff then 0000001.miff etc, but not sure how to do this.

Any tips would be very welcome. One thing I do know about linux is the more familiar you get with bash, the less heavy GUI apps you need. Bash is awesome!
 
Old 03-23-2006, 12:55 PM   #2
demian
Member
 
Registered: Apr 2001
Location: Bremen, Germany
Distribution: Debian
Posts: 303

Rep: Reputation: 30
uhm you mean date?

Code:
demian@dirac:~$ date
Thu Mar 23 19:54:17 CET 2006
demian@dirac:~$ date "+%y%m%d"
060323
demian@direac:~$ date "+%y%m%d-%H%M%S%N"
060323-195435665289000
demian@dirac:~$
edit: oh, and to include that in a filename just do something like

ts=`date "+%y%m%d-%H%M%S%N"`
import yadayada something-$ts.png

in your script

Last edited by demian; 03-23-2006 at 12:58 PM.
 
Old 03-23-2006, 01:14 PM   #3
smudge|lala
Member
 
Registered: Jan 2004
Location: New Zealand
Distribution: Mint | Sabayon
Posts: 160

Original Poster
Rep: Reputation: 16
Adding timestamp to script

Thank you Demian.

My script currently contains:

let x=1

while [ "$x" -le "$2" ]
do
import -window $1 "image$x.miff"


so to add timestamp into the filename,

let x=1

while [ "$x" -le "$2" ]
do
import -window $1 | date "+%y%m%d-%H%M%S%N" | $.miff"
or >> or something?

Not sure if that is right? One other query, in specifying the capture, is there a way of knowing at what rate a capture is taken without working out the timestamps? I mean my system will capture at 400 FPS or 5 FPS?

while [ "$x" -le "$2" ] is missing some functionality I think!

Last edited by smudge|lala; 03-23-2006 at 02:21 PM.
 
Old 03-23-2006, 04:13 PM   #4
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
import -window $1 "`date +%y%m%d-%H%M%S%N`.miff" should work, I think.
 
Old 03-23-2006, 04:31 PM   #5
smudge|lala
Member
 
Registered: Jan 2004
Location: New Zealand
Distribution: Mint | Sabayon
Posts: 160

Original Poster
Rep: Reputation: 16
Works a treat, thank you mikshaw. I knew I had a syntax issue!
 
Old 03-23-2006, 04:48 PM   #6
demian
Member
 
Registered: Apr 2001
Location: Bremen, Germany
Distribution: Debian
Posts: 303

Rep: Reputation: 30
Quote:
Originally Posted by smudge|lala
import -window $1 | date "+%y%m%d-%H%M%S%N" | $.miff"[/b] or >> or something?

Not sure if that is right? One other query, in specifying the capture, is there a way of knowing at what rate a capture is taken without working out the timestamps? I mean my system will capture at 400 FPS or 5 FPS?
import -window $1 `date "+%H%M%S%N"`-$x.miff

can't you just divide the mumber of output file by the time the script runs?

time ./your-script.sh
 
Old 03-23-2006, 07:16 PM   #7
smudge|lala
Member
 
Registered: Jan 2004
Location: New Zealand
Distribution: Mint | Sabayon
Posts: 160

Original Poster
Rep: Reputation: 16
Timing of import xsession

It could be used that way I guess. I think the most accurate way is to sort the import images with another script as they have such accurate timestamps. This will take some working out!

I'm pretty new with bash scripting, but have to learn as there are so many things the command line can offer.

Looking at my earlier script, I have to input two variables. The first to specify the active window, 0x320003b or something, and the amount of captures I want to make, 50, 100, whatever. I'd like to add into the script extra functionality with echo for the variables.

The first is after I run the script $ ./import.sh to run xwininfo automatically so I can select the window, then for it to automatically use the 0x320003b or whatever window ID found in xwininfo, and ask 'how many captures?' I can type the quantity AND an output directory, hit return and start importing!

Bit of a job, but I think it's all bash, nothing external. Not sure how to crop the window ID 0x320003b

Usually a bit long. A typical output:

Code:
xwininfo: Window id: 0x320003b "LinuxQuestions.org - Reply to Topic - Firefox"

  Absolute upper-left X:  198
  Absolute upper-left Y:  117
  Relative upper-left X:  0
  Relative upper-left Y:  0
  Width: 955
  Height: 762
  Depth: 16
  Visual Class: TrueColor
  Border width: 0
  Class: InputOutput
  Colormap: 0x20 (installed)
  Bit Gravity State: NorthWestGravity
  Window Gravity State: NorthWestGravity
  Backing Store State: NotUseful
  Save Under State: no
  Map State: IsViewable
  Override Redirect State: no
  Corners:  +198+117  -127+117  -127-145  +198-145
  -geometry 955x762+195+94

Last edited by smudge|lala; 03-24-2006 at 10:05 AM.
 
Old 03-23-2006, 08:15 PM   #8
demian
Member
 
Registered: Apr 2001
Location: Bremen, Germany
Distribution: Debian
Posts: 303

Rep: Reputation: 30
Code:
#!/bin/sh

echo "Click the window you want to capture..."

winid=`xwininfo |awk '{if(NR==6)print $4}'`

echo -n "Enter the number of captures: "
read numcap

echo "capturing $numcap frames of window $winid"

start=`date "+%s.%N"`
for i in `seq $numcap`
do
  import -window $winid `date "+%H%M%S%N"`-$i.miff
done
stop=`date "+%s.%N"`

echo "Capture took `echo "scale=5;($stop-$start)/$numcap"|bc` seconds per frame"
edit: I just read the import man page and found out about the -snaps option. So you can forget the entire for loop and replace that with

import -window $winid -snaps $numcap filename.miff

it will create files named filename-0.miff through filename-$numcap.miff automatically. You can, of course, still prefix it with the date string if you whish.

Last edited by demian; 03-23-2006 at 08:35 PM.
 
Old 03-23-2006, 09:30 PM   #9
smudge|lala
Member
 
Registered: Jan 2004
Location: New Zealand
Distribution: Mint | Sabayon
Posts: 160

Original Poster
Rep: Reputation: 16
Works a treat! Handy to swap between the two as the snap makes a single large file, but easily converted into a mng. Creates a file called filename.miff. Any way to echo 'output filename'?

Last edited by smudge|lala; 03-23-2006 at 11:01 PM.
 
Old 03-23-2006, 09:41 PM   #10
demian
Member
 
Registered: Apr 2001
Location: Bremen, Germany
Distribution: Debian
Posts: 303

Rep: Reputation: 30
Quote:
Originally Posted by smudge|lala
Works a treat! Handy to swap between the two as the snap makes a single large file, but easily converted into a mng. Creates a file called filename.miff.
ok, i only tried it with png files since miff are so large. they are stored in a single file per capture.
Quote:
Anyway to echo 'output filename'?
You mean have the script ask for the filename? Sure, that's possible, however, I think I've done enough of your work. With the above you've got more than enough info to take it from here.
http://www.tldp.org/LDP/abs/html/
 
Old 03-23-2006, 09:48 PM   #11
smudge|lala
Member
 
Registered: Jan 2004
Location: New Zealand
Distribution: Mint | Sabayon
Posts: 160

Original Poster
Rep: Reputation: 16
Thanks for all your help Demian, great stuff!
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Handling filename beginning with '--' in bash vjimin Linux - Newbie 2 02-07-2006 04:18 AM
Getting the first part of a filename in a BASH script trevelluk Programming 3 02-15-2005 01:06 AM
using bash in cron to get the date in filename rstoutmna Programming 1 12-29-2004 02:39 PM
adding date timestamp to filename markraem Solaris / OpenSolaris 2 11-17-2004 08:32 AM
Bash commands not include??? fxlee Linux - Newbie 4 10-26-2001 10:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:43 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