- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- cron question
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
07-03-2005 11:00 AM
07-03-2005 11:00 AM
How can I do this from a command line?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2005 01:40 PM
07-03-2005 01:40 PM
Re: cron question
If you really cannot write in a tempfile, the only solution is to leave space in your file upon creation to hold this second line. You can leave a long empty string at line 2, ended by a newline. Then you can open it, goto line 2 and replace it with your string, padded to have the same length. I don't think any shell tool can pull this off easily, so I suggest you try perl. :)
If you can write to another file, the simplest way I can think of is using awk like this:
cat original_file | awk '{
print;
print "";
while (getline)
{
print;
}
}' > new_file
mv new_file original_file
I don't have a prompt at hand so there might be a syntax error or two.
Good luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2005 04:58 PM
07-03-2005 04:58 PM
Re: cron question
Can't give a full solution but maybe some points might click.
Since cron will be writing to that file, you can't do anything with that otherwise your cron will stop.
So use "fuser" to find out whether at that moment that file is being used. If not append the line after the first one.
It can be done by sed but at the moment i don't remember the syntax.
So something like
if fuser filename
then
sed ...
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2005 11:28 PM
07-03-2005 11:28 PM
Re: cron question
what about this? zz is old and zz1 is new file.
greetings,
Michael
#!/bin/ksh -xu
typeset -i10 LC=`wc -l zz|awk '{print $1}'`
let LC=LC-1
head -1 zz > zz1
print "insert line" >> zz1
tail -${LC} zz >> zz1
mv zz1 zz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2005 11:36 PM
07-03-2005 11:36 PM
Re: cron question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2005 11:54 PM
07-03-2005 11:54 PM
Re: cron question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2005 12:05 AM
07-04-2005 12:05 AM
SolutionSo you can create the file as
touch exp
sed -e 's/text_to_replace/^/g'
Now start your cron job, which will add test to this file.
When your cron has completed, if you really want this to be 2nd one, add the first line using the same sed command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2005 12:14 AM
07-04-2005 12:14 AM
Re: cron question
this makes it a lot easier
print "insert line" > new_file
cat old_file >> new_file
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2005 01:20 AM
07-04-2005 01:20 AM
Re: cron question
I love this forum. When I post here, I always get a solution or plenty of good ideas to solve the issue at hand!!!
Again, thank you from the guy who wishes he was a scripter!!!!!
Chuckle, chuckle, chuckle....