Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2002 11:27 PM
08-12-2002 11:27 PM
I have three files a.txt b.txt c.txt and a shell script run.sh .
The file c.txt is empty. My requirement - When
I run run.sh once the cotents of file a.txt should be in c.txt. And If run run.sh second time the contents of b.txt should be in c.txt.
The order of file content of c.txt should be in round robin (a.txt->c.txt,b.txt->c.txt,a.txt->c.txt.....so on) every time I execute the run.sh.
So what can be the shell script for run.sh ?.
regards,
U.SivaKumar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2002 11:50 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2002 11:53 PM
08-12-2002 11:53 PM
Re: puzzle
Well done Sir.
What happens if my a.txt and b.txt are of same size ?.
regards,
U.SivaKumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2002 11:53 PM
08-12-2002 11:53 PM
Re: puzzle
I would maintain a checkfile which only holds the last copied file. Then in the script you can check on this content.
Another option is to change a bit on the c.txt file. Like the sticky bit or the x-bit. And in the script check on this bit.
Good luck
Donald
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2002 11:56 PM
08-12-2002 11:56 PM
Re: puzzle
You need to store the laste state somewhere... or you could use diff to get the last cp state (would be inefficient with large files!).
Idea: hold a state file.
#!/usr/bin/sh
if [[ "$(cat nextfile 2>/dev/null)" = b.txt ]]; then
cp b.txt c.txt
echo a.txt >nextfile
else
cp a.txt c.txt
echo b.txt >nextfile
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2002 11:57 PM
08-12-2002 11:57 PM
Re: puzzle
For your script to know which file to write from, it will have to know which file was written from last time. I would set this in a variable or a file. If the script needs to work for differnent users or sessions it would have to be in a file.
Therefore I'd do somthing like this:
if [ ! -f last_written_from ] ; then
echo b > last_written_from
fi
if [ "$(cat last_written_from)" = "b" ] ; then
cp a.txt c.txt
echo a > last_written_from
else
cp b.txt c.txt
echo b > last_written_from
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2002 11:59 PM
08-12-2002 11:59 PM
Re: puzzle
if [ -s c.txt ]; then
echo "CHANGING"
file=$(ls -1rt a.txt b.txt|head -1)
cat $file >c.txt
touch $file
else
cat a.txt >c.txt
touch a.txt
fi
sleep 1 #
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2002 12:06 AM
08-13-2002 12:06 AM
Re: puzzle
2. use MD5 or sum + timestamp to identify which file is in c.txt
3. use tar or cpio instead of cp to maintan access and modification times, so you can use these to check
4. use a stampfile in which you state what the next file will be (or what the last file was)
5. use symlinks :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2002 12:07 AM
08-13-2002 12:07 AM
Re: puzzle
diff compares the contents of the files.
Regards,
Trond
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2002 06:38 PM
08-13-2002 06:38 PM
Re: puzzle
#!/usr/bin/sh
if [ -e a.txt -a -e b.txt ]
then
if [ a.txt -ef c.txt ]
then
ln -f b.txt c.txt
else
ln -f a.txt c.txt
fi
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2002 11:38 PM
08-13-2002 11:38 PM
Re: puzzle
if diff b.txt c.txt 2>/dev/null
then cp a.txt c.txt
else cp b.txt c.txt
fi
this is beautiful scripting indeed ;)
Thanks King John.
Best Regards
Yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2002 12:06 AM
08-14-2002 12:06 AM
Re: puzzle
if cmp -s b.txt c.txt
then cp a.txt c.txt
else cp b.txt c.txt
fi
Linking the files may be OK but if there is any intention to alter the contents of c.txt then the linked original file gets changed as well.
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2002 01:05 AM
08-14-2002 01:05 AM
Re: puzzle
l1:/u/usr/merijn 126 > perl -we '$a=(readlink($c="c.txt"))=~/^a/?"b":"a";unlink$c;symlink"$a.txt",$c' ; ll *.txt
1363 -rw-rw-rw- 1 merijn softwr 64 Aug 14 10:48 a.txt
1420 -rw-rw-rw- 1 merijn softwr 64 Aug 14 10:49 b.txt
1423 lrwxrwxrwx 1 merijn softwr 5 Aug 14 11:10 c.txt -> a.txt
l1:/u/usr/merijn 127 > perl -we '$a=(readlink($c="c.txt"))=~/^a/?"b":"a";unlink$c;symlink"$a.txt",$c' ; ll *.txt
1363 -rw-rw-rw- 1 merijn softwr 64 Aug 14 10:48 a.txt
1420 -rw-rw-rw- 1 merijn softwr 64 Aug 14 10:49 b.txt
1423 lrwxrwxrwx 1 merijn softwr 5 Aug 14 11:10 c.txt -> b.txt
l1:/u/usr/merijn 128 > perl -we '$a=(readlink($c="c.txt"))=~/^a/?"b":"a";unlink$c;symlink"$a.txt",$c' ; ll *.txt
1363 -rw-rw-rw- 1 merijn softwr 64 Aug 14 10:48 a.txt
1420 -rw-rw-rw- 1 merijn softwr 64 Aug 14 10:49 b.txt
1423 lrwxrwxrwx 1 merijn softwr 5 Aug 14 11:10 c.txt -> a.txt
l1:/u/usr/merijn 129 >