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.
First, the loop you are using is useless. You command can be written as:
This will not work. You need to use the following command instead to create the file as root:
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 usetee -a
to work in append mode if needed to replace>>
.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.