|
Home > Archive > Unix Programming > January 2007 > Deleting the contents of one file from another
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Deleting the contents of one file from another
|
|
| sonyantony@hotmail.com 2007-01-29, 1:33 am |
| I m using ksh on Solaris.
I m trying to remove my entries from crontab.
All my entries are contained in a file my_crontab_jobs.txt
So I need to do something like
crontab -l | delete_entries_from my_crontab_jobs.txt|crontab
Is there any way to do it in one like ( like cut, paste, diff etc )
Thanks
--sony
| |
| Chris F.A. Johnson 2007-01-29, 1:33 am |
| On 2007-01-29, sonyantony@hotmail.com wrote:
> I m using ksh on Solaris.
>
> I m trying to remove my entries from crontab.
> All my entries are contained in a file my_crontab_jobs.txt
> So I need to do something like
>
> crontab -l | delete_entries_from my_crontab_jobs.txt|crontab
If you have a file with your crontab entries, you don't want to use
crontab -l.
If you want to remove all your crontab entries:
> my_crontab_jobs.txt
crontab my_crontab_jobs.txt
If you want to remove selected entries:
pat1=XXXXXX ## Where XXXXX identifies a line you want to remove from the file.
pat2=YYYYYY ## YYYYYY ditto
cp my_crontab_jobs.txt my_crontab_jobs.tmp
sed -e "/$pat1/d" -e "/$pat2/d" my_crontab_jobs.tmp > my_crontab_jobs.txt
crontab my_crontab_jobs.txt
> Is there any way to do it in one like ( like cut, paste, diff etc )
Do you mean one _line_? If so, why? There's no advantage to keeping
it on a single line.
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
| |
| Logan Shaw 2007-01-29, 1:33 am |
| sonyantony@hotmail.com wrote:
> I m using ksh on Solaris.
>
> I m trying to remove my entries from crontab.
> All my entries are contained in a file my_crontab_jobs.txt
> So I need to do something like
>
> crontab -l | delete_entries_from my_crontab_jobs.txt|crontab
Why do you think you need to do something like the above. If
all your crontab entries are in a text file already, there is no
need to run "crontab -l", because that just lists crontab entries,
which you don't care about.
The most obvious way to do it would be to just edit the
text file that contains the crontab entries, then re-import
them into the system's copy of your crontab file with
the "crontab" command. If that isn't sufficient for what
you're trying to do, could you explain more clearly what
you're trying to accomplish?
- Logan
| |
| sonyantony@hotmail.com 2007-01-29, 1:33 am |
|
Thank you very much for the responses.
There is no reason why I wanted to do in one line, except that I
thought it will be cool, and took it as a challenge.
Why I wanted to do
crontab -l | delete_entries_from my_crontab_jobs.txt|crontab
is because crontab -l will give my jobs along with others job.
Then I will just delete my ones from it and teh result used to replace
the crontab entries.
Actually I have solved the problem by adding a comment like
#MY_CRONTAB_ENTRIES at the end.
mycrontabfile.txt will contain entries of the like.
* * * * * my_script_to_be_run #MY_CRONTAB_ENTRIES
These entries are added to the crontab as
crontab -l|cat - mycrontabfile.txt |sort -u|crontab
And to remove my entries without affecting others' entries..
crontab -l | grep -v MY_CRONTAB_ENTRIES |crontab
Thank you again
--sony
On Jan 28, 11:54 pm, Logan Shaw <lshaw-use...@austin.rr.com> wrote:
> sonyant...@hotmail.com wrote:
>
>
> all your crontab entries are in a text file already, there is no
> need to run "crontab -l", because that just lists crontab entries,
> which you don't care about.
>
> The most obvious way to do it would be to just edit the
> text file that contains the crontab entries, then re-import
> them into the system's copy of your crontab file with
> the "crontab" command. If that isn't sufficient for what
> you're trying to do, could you explain more clearly what
> you're trying to accomplish?
>
> - Logan
| |
| Gordon Burditt 2007-01-29, 1:33 am |
| >There is no reason why I wanted to do in one line, except that I
>thought it will be cool, and took it as a challenge.
>Why I wanted to do
>crontab -l | delete_entries_from my_crontab_jobs.txt|crontab
Are you *absolutely sure* that the last crontab on the line won't
open the crontab for destructive write before the first crontab on the
line manages to read it? I've been bitten by things like this before,
and ended up with an empty file.
| |
| Stephane CHAZELAS 2007-01-29, 7:20 am |
| 2007-01-28, 18:57(-08), sonyantony@hotmail.com:
> I m using ksh on Solaris.
>
> I m trying to remove my entries from crontab.
> All my entries are contained in a file my_crontab_jobs.txt
> So I need to do something like
>
> crontab -l | delete_entries_from my_crontab_jobs.txt|crontab
>
> Is there any way to do it in one like ( like cut, paste, diff etc )
[...]
crontab -l | grep -Fxvf my_crontab_jobs.txt | crontab
--
Stéphane
| |
| Ralf Fassel 2007-01-29, 7:20 am |
| * sonyantony@hotmail.com
| Why I wanted to do
| crontab -l | delete_entries_from my_crontab_jobs.txt|crontab
| is because crontab -l will give my jobs along with others job.
'crontab -l' will only list entries for a single user (the user id
you're logged in, or for the argument of -u when running as root).
No way you can see other's crontab entries when running as ordinary
user.
| Then I will just delete my ones from it and teh result used to
| replace the crontab entries.
If you want to remove your crontab completely, use 'crontab -r'.
R'
| |
| Kenny McCormack 2007-01-29, 7:20 am |
| In article <yga1wleruse.fsf@panther.akutech-local.de>,
Ralf Fassel <ralfixx@gmx.de> wrote:
>* sonyantony@hotmail.com
>| Why I wanted to do
>| crontab -l | delete_entries_from my_crontab_jobs.txt|crontab
>| is because crontab -l will give my jobs along with others job.
>
>'crontab -l' will only list entries for a single user (the user id
>you're logged in, or for the argument of -u when running as root).
>No way you can see other's crontab entries when running as ordinary
>user.
In some shops, all the cronjobs are run as a single user (e.g., root),
rather than having each user maintain their own crontab file. It sounds
like that is the case here, and the OP wants to remove "his" jobs from
the master file.
>| Then I will just delete my ones from it and teh result used to
>| replace the crontab entries.
>
>If you want to remove your crontab completely, use 'crontab -r'.
Probably not a good idea. See above.
| |
| sonyantony@hotmail.com 2007-01-29, 1:17 pm |
| Thank you very much for the answers.
grep -Fxvf is exactly what I was looking for. Thanks Stephane.
I have decided not to use one line though, because of the problem=20
Gordon pointed out. Thanks for that Gordon. ( although I found it to=20
be working fine )
And yes each user has his own crontab file.
My concern was that, since this is a common user used by other folks=20
as well, I was afraid that I might end up removing some other's ( put=20
as the same user ) jobs.
Thanks everybody
--sony
On Jan 29, 3:52 am, Stephane CHAZELAS <this.addr...@is.invalid> wrote:
> 2007-01-28, 18:57(-08), sonyant...@hotmail.com:> I m using ksh on Solaris.
>
>
>
>
> crontab -l | grep -Fxvf my_crontab_jobs.txt | crontab
>
> --
> St=E9phane
| |
| Barry Margolin 2007-01-30, 1:27 am |
| In article <1170090812.361398.190320@l53g2000cwa.googlegroups.com>,
sonyantony@hotmail.com wrote:
> Thank you very much for the answers.
> grep -Fxvf is exactly what I was looking for. Thanks Stephane.
> I have decided not to use one line though, because of the problem
> Gordon pointed out. Thanks for that Gordon. ( although I found it to
> be working fine )
I'm pretty sure Gordon's issue isn't a problem. Crontab checks the
syntax of the input before it updates the crontab file. Also, if it's
taking input from the terminal, you can Control-C out of it and your
crontab file will be unchanged. These behaviors require that it not
truncate the crontab file until it has read all of stdin and it's ready
to update it.
[vbcol=seagreen]
>
> And yes each user has his own crontab file.
> My concern was that, since this is a common user used by other folks
> as well, I was afraid that I might end up removing some other's ( put
> as the same user ) jobs.
> Thanks everybody
> --sony
>
>
> On Jan 29, 3:52 am, Stephane CHAZELAS <this.addr...@is.invalid> wrote:
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
|
|
|
|
|