Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Now i wated to schedule cronjob for the same. But the cronjob always try to run as root user, how to make cronjob to run as 'saggu' user and after the cronjob success i wanted to change the owner ships of the csv file. how to do it in a best way
i have added the cronjob under /etc/crontab, i used it as sudo /etc/crontab to edit crontab. I am not able to use crontab as saggu user, it allows me to edit and save , i also see 'installing as new crontab' but nothing changes. when i look again using 'crontab -l' i see no crontab for saggu
I used ssh keys
FYI: user cron jobs are normally maintained using the crontab command, rather than manually manipulating files. Crontab has some syntax and issue checking, but it is always better to not depend upon that.
Simplest would be to switch to your user's cron job instead of system cron.
yes it works with the user crontab, but the problem is after scp i would need to modify the file permissions and ownerships which is only possible with sudo user then
yes it works with the user crontab, but the problem is after scp i would need to modify the file permissions and ownerships which is only possible with sudo user then
Why?
The permissions can be set before transfer, and the ownership depends upon the account on the remote host.
If you want to change the owner of the file then you need to run the cron job as root. Create a script that includes scp and your chown command and then run it as root in /etc/crontab.
If I run a cronjob in /etc/crontab as my user i.e.
* * * * * user scp ...
or in my users crontab the permissions are the same i.e.
My scp man page mentions the -p option, which preserves the owner and group, and permissions. If those are set properly for the target location and ownership (may have to set numerically) and you scp it using the -p option then it should land with the proper ownership and permission. (Under some conditions the advantage may be sending TO the root account on the remote machine, so the authority to force that is in place, but I cannot test on your hosts to make sure if that might be required for your case.)
My OpenSSH version (source of the scp command) is 9.1p1.
I hope that helps.
Note that this ownership and permission issue is an enhancement or expansion of the original question. You might work on including ALL of the requirements in the original post for future questions.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.