[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Linux SED command help

Posted on 2011-04-26
5
Medium Priority
?
464 Views
Last Modified: 2013-12-05
Have a crontab job that runs every night at 5am and deletes any files in the temp folder older than 15 days. Problem is that we've been recieving e-mail alerts (e-mail configured in /etc/aliases sent to root) every time a file is in use.. We don't want tog et these alerts so I want to re-direct them to /dev/null .

Crontab entry:
00 05 * * *     root find /tmp -mtime +15 -prune -exec rm -Rf {} >/dev/null   /;
PS: The syntax above to re-direct errors is wrong.

So I'm trying to run a script to change that line in every crontab on every server.
Problem is with the & character. In SED, this character is considered a replacement character.
I would like for sed to use it as fixed character.

Here's the command I'm using in my script:

sed -i \"s#{} >/dev/null#>{} >/dev/null 2>&1#\"

I tried a few things, like using ascii codes, or putting '&' in the string.. After searching on google and expert exchange for a few hours. and trying many things.. Can't seem to get this to work. Anyone know how to fix this?

Thank you,


Erik

0
Comment
Question by:trembe
  • 3
5 Comments
 
LVL 8

Accepted Solution

by:
pilson66 earned 252 total points
ID: 35466506
try:
sed -i \"s#{} >\/dev\/null#\>{}\ \>\/dev\/null 2\>\&1#\"
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35466526
Try this:
 sed  "s#{} >/dev/null#>{} >/dev/null 2>\&1#"
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35466560
Sorry, I removed -i

Here it is:

sed  "s#{} >/dev/null#>{} >/dev/null 2>\&1#"

Open in new window

0
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 248 total points
ID: 35466564
Oops
sed -i "s#{} >/dev/null#>{} >/dev/null 2>\&1#"
0
 

Author Comment

by:trembe
ID: 35466587
Thank you both. works great.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question