LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using dd command to create a .sequence file (https://www.linuxquestions.org/questions/linux-newbie-8/using-dd-command-to-create-a-sequence-file-759214/)

zeus65 10-02-2009 09:46 AM

Using dd command to create a .sequence file
 
Hi Everyone, firstly like to say Hi can't say how many times I've randomly searched for something via google and got the answer on this forum... its a lot :)

I know there is a major thread on how dd works but I'm really confused by it in terms of what I'm trying to do


Basically I've inherited this concept where say in a dir
/var/spool/send

a person runs this command dd if=/dev/zero of=.sequence bs=8 count=1


Now what I inherited is a binary c file that can lock this .sequence, print out the number 'stored', and bump up the number. Unfortunately I don't have access to the original c code source currently and considering I'm just trying to duplicate into java.


e.g
first time program runs it just prints out

00000000000000000000


second prints out

00000000000000000001

The idea is to create a sequencing filename mechanism. So if I was spooling a bunch of files to a web service or some sort of socket the program writing to the files would first use 00000000000000000000 as the file name then 00000000000000000001 for second ...



Now I'm trying to figure out how this was done in the c program and actually do the same thing in java.

I noticed something in the forum message but I'm not sure how it correlates

zeus@pandion:~/tests$ hexdump .sequence
0000000 0002 0000 0000 0000
0000008


Thanks guys this is probably something so simple but...

JulianTosh 10-02-2009 11:57 PM

It seems there's a bunch of unnecessary information in this post. Can you confirm my interpretation please?

You want a java program to open a file, read an integer, increment it, write it to the file, and then display it?

zeus65 10-03-2009 03:37 PM

Thanks
 
Hi Admiral yeah pretty much. I was just trying follow the same mechanism we have today in the system. Guess it doesn't really need to rely on a dd sequence file at all when you put it like that :).

JulianTosh 10-03-2009 06:08 PM

I know you asked for it in Java, but here it is in a bash script:

Code:

#!/bin/bash

if ! [ -f tmp/.sequence ]; then
  echo 0 > tmp/.sequence
fi

counter=$(cat tmp/.sequence)
counter=$(($counter + 1))
echo $counter | tee tmp/.sequence


zeus65 10-05-2009 04:38 AM

Thanks Admiral that is pretty much what I will use.


Jason


All times are GMT -5. The time now is 08:17 AM.