-1

I have just set up the .com of a domain that previous ran on .co.uk on the same server, I have copied all the files, ran through them using bash to change the domain anywhere it was referenced, same for DB, and all went great, same with the redirect. But now I want to move the cron jobs across using bash.

I was thinking

sudo cat /var/spool/cron/sbadmin | while read -r line; do echo $line;done > /var/spool/cron/sbcomadmin

But permission is denied on the new file. How can permission be denied when I am in sudo mode?

The domain will need changing in the new cron file aswell but I was thinking I could use sed on that, either during the copy or after.

2 Answers 2

1

First, the loop you are using is useless. You command can be written as:

$ sudo cat /var/spool/cron/sbadmin > /var/spool/cron/sbcomadmin

This will not work. You need to use the following command instead to create the file as root:

$ cat /var/spool/cron/sbadmin | sudo tee /var/spool/cron/sbcomadmin

The tee will write the output to both stdout and the provided file. If you don't want to write to stdout, you can append > /dev/null at the end of the previous command. Also, you can use tee -a to work in append mode if needed to replace >>.

4
  • Great thanks. I just added to my question, I need to change the domains in the cron file from mydomain.co.uk to mydomain.com, I was thinking maybe use sed, is there anyway I can incorporate this into the same command. Dec 23, 2012 at 15:25
  • @LiamBailey: Yes, you can use sed in the command. So it comes cat file | sed 's/co.uk/com/' | sudo tee file.
    – Khaled
    Dec 23, 2012 at 15:59
  • so, just to confirm if I didn't want the output the command would be `cat /var/spool/cron/sbadmin > /dev/null | sudo tee /var/spool/cron/sbcomadmin or would the > /dev/null go after the filename on sudo tee? Dec 23, 2012 at 21:11
  • @LiamBailey: The 2nd one.
    – Khaled
    Dec 24, 2012 at 7:52
0

Assumming the userids and group information are the same.....have you thought of using cpio or tar...make the archive....send it to the other system.....restore it....make the minor edits....done. A shell loop like this is not a very efficient method especially if there are a large number of files.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .