LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-06-2018, 07:38 AM   #1
dr-artsi
LQ Newbie
 
Registered: Oct 2018
Posts: 7

Rep: Reputation: Disabled
How to make custom crontab entry persistent


Hi
I'm new to Linux, and took on something that seemed like a simple task, but became very difficult in practice.

I have a NAS (Zyxel NSA325v2), which runs a light version of linux, BusyBox v1.17.2. Latest firmware offered by Zyxel is installed on the NAS. I'm logged in through SSH as root.

The task is to have the NAS execute a custom python script every 15 minutes using crontab. The problem I'm facing is that the custom crontab entry isn't persistent -- it vanishes when the NAS reboots.

The crontab where I put my custom entry resides in /var/spool/cron/crontabs/root. It has eight default entries that are persistent.

I have been able to track a file that writes some of these default entries: /ram_bin/etc/init.d/rcS2
I tried to mimic those default entries and added my custom entry in that file, but faced an issue when saving the changes: "Read-only filesystem". After googling I found that "more /etc/fstab" and "mount -l" give info about the mounts taking place in boot and the currently mounted filesystems, respectively. Scroll down for outputs of those commands.

So indeed the /ram_bin is read-only. Further googling revealed that "mount -o remount,rw" can help, but I wasn't able to find correct syntax that would do the trick.

So, my actual question is: Should I continue to try make the filesystem read-write to be able to modify rcS2 file, or is there an alternative solution to my actual problem -- getting the crontab entry persistent? Please help.



/ # more /etc/fstab
/dev/ram0 / ext2 defaults 0 0
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
none /dev/pts devpts defaults 0 0



/ # mount -l
rootfs on / type rootfs (rw)
/proc on /proc type proc (rw,relatime)
/sys on /sys type sysfs (rw,relatime)
none on /proc/bus/usb type usbfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,mode=600)
/dev/mtdblock6 on /zyxel/mnt/nand type yaffs2 (ro,relatime)
/dev/sda1 on /zyxel/mnt/sysdisk type ext2 (ro,relatime,errors=continue)
/dev/loop0 on /ram_bin type ext2 (ro,relatime,errors=continue)
/dev/loop0 on /usr type ext2 (ro,relatime,errors=continue)
/dev/loop0 on /lib/security type ext2 (ro,relatime,errors=continue)
/dev/loop0 on /lib/modules type ext2 (ro,relatime,errors=continue)
/dev/ram0 on /tmp/tmpfs type tmpfs (rw,relatime,size=5120k)
/dev/ram0 on /usr/local/etc type tmpfs (rw,relatime,size=5120k)
/dev/ram0 on /usr/local/var type tmpfs (rw,relatime,size=5120k)
/dev/mtdblock4 on /etc/zyxel type yaffs2 (rw,relatime)
/dev/md0 on /i-data/d3b34c71 type ext4 (rw,noatime,barrier=0,data=writeback,usrquota)
/dev/md0 on /usr/local/zy-pkgs type ext4 (rw,noatime,barrier=0,data=writeback,usrquota)
/dev/md0 on /etc/zyxel/zy-pkgs type ext4 (rw,noatime,barrier=0,data=writeback,usrquota)
/dev/md0 on /usr/local/apache/htdocs/adv,/pkg type ext4 (rw,noatime,barrier=0,data=writeback,usrquota)
/dev/md0 on /usr/local/apache/web_framework/data/cache type ext4 (rw,noatime,barrier=0,data=writeback,usrquota)
/dev/mtdblock4 on /usr/local/apache/web_framework/data/config type yaffs2 (rw,relatime)
/dev/md0 on /usr/local/apache/htdocs/adv,/res/imdb_poster type ext4 (rw,noatime,barrier=0,data=writeback,usrquota)
 
Old 10-06-2018, 07:58 AM   #2
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
I think you have more or less answered your own question, and clearly have done some very good research on it - which is very refreshing to see, well done.

The "Read-only filesystem" message means that even with "root" permissions, you cannot change/modify any files on that filesystem. So yes I'd agree that you need to mount the filesystem as read-write - if possible. I will admit that I don't have much experience with Busybox or NAS devices, so my help might be limited there.

The other thing is that as far as cron jobs are concerned, to my understanding, you would need to drop the cron job in one of the /etc/cron.X folders - change "cron.X" to "cron.daily", "cron.hourly", or whatever applies to you.

My /etc/fstab file as follows;

Code:
UUID=14ea7d36-8c7a-4269-a1f1-cb2ec439addb /                       ext4    defaults        1 1
/dev/mapper/luks-58fab0de-0178-403a-a56b-0beecb5c09e3 /home                   ext4    defaults,x-systemd.device-timeout=0 1 2
UUID=f8d1913b-c293-48e7-a2b0-7f6407c9dd07 swap                    swap    defaults        0 0
UUID=95142a76-929f-495a-83db-48d71752a83b /other_hdd_drives/multimedia ext4 defaults 1 2
I've highlighted my "root partition" in bold for you. It's the same syntax regardless of the Linux distribution concerned as far as I know.
 
Old 10-06-2018, 10:02 AM   #3
dr-artsi
LQ Newbie
 
Registered: Oct 2018
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thanks for a quick response! Greatly appreciated!

So, what you propose is to
1. add my cron job to /etc/cron.quarter_hourly, and
2. make the /dev/loop0 mount in /ram_bin read-write

I have follow-up questions on both:
1. What exactly is the "cron job"? Is that a file containing the crontab entry, or the target of the cron job i.e. the python script, or is it something else? Currently there are no folders named cron.X in /etc/ so it seems to me that is not the solution since there are eight default crontab entries.
2. I have tried various forms of "mount -o remount,rw" but none seem to do the trick. I've tried to give it the mount point /ram_bin and the mounted device /dev/loop0 as arguments but nothing seems to happen. What is the correct syntax and does it matter what the current folder is when executing the command?
 
Old 10-06-2018, 10:10 AM   #4
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
Quote:
Originally Posted by dr-artsi View Post
Thanks for a quick response! Greatly appreciated!

So, what you propose is to
1. add my cron job to /etc/cron.quarter_hourly, and
2. make the /dev/loop0 mount in /ram_bin read-write

I have follow-up questions on both:
1. What exactly is the "cron job"? Is that a file containing the crontab entry, or the target of the cron job i.e. the python script, or is it something else? Currently there are no folders named cron.X in /etc/ so it seems to me that is not the solution since there are eight default crontab entries.
2. I have tried various forms of "mount -o remount,rw" but none seem to do the trick. I've tried to give it the mount point /ram_bin and the mounted device /dev/loop0 as arguments but nothing seems to happen. What is the correct syntax and does it matter what the current folder is when executing the command?
I'm not sure the "/etc/cron.quarter_hourly" is valid.

Yes, you should make the "root filesystem" read-write if possible, as you will not otherwise have permission to modify fstab. Depending on the device and/or system running on it, it may not be possible - once again, I don't have a NAS device to play with myself.

A cron job is basically a shell script that cron/anacron runs at particular intervals.

Have a look at the example fstab I gave you in my post above. You should mount via UUID's instead of the device node.
 
Old 10-06-2018, 11:19 AM   #5
dr-artsi
LQ Newbie
 
Registered: Oct 2018
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jsbjsb001 View Post
I'm not sure the "/etc/cron.quarter_hourly" is valid.

Yes, you should make the "root filesystem" read-write if possible, as you will not otherwise have permission to modify fstab. Depending on the device and/or system running on it, it may not be possible - once again, I don't have a NAS device to play with myself.

A cron job is basically a shell script that cron/anacron runs at particular intervals.

Have a look at the example fstab I gave you in my post above. You should mount via UUID's instead of the device node.
I don't know how to find the correct UUID's. Also the root filesystem seems to be read-write already. It's some other filesystems mounted on various folders that are read-only. I am able to modify /etc/fstab, but the changes I make aren't persistent.

I think I now have my answer on the filesystems: it's not possible to make /ram_bin read-write, scroll down to the last command.

Here are a few commands and corresponding outputs that I tried:

mount -o remount,rw

-outputs a long help text about mount
-no changes occured in the list given by "mount -l"


mount -o remount,rw -t ext2 /dev/ram0 /

-gives no output
-no changes occured in the list given by "mount -l"


mount -o remount,rw -t ext2 /dev/loop0 /

-gives no output
-no changes occured in the list given by "mount -l"


mount -o remount,rw -t ext2 /dev/loop0 /ram_bin
mount: block device /dev/loop0 is write-protected, mounting read-only
 
Old 10-06-2018, 11:26 AM   #6
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
Quote:
Originally Posted by dr-artsi View Post
I don't know how to find the correct UUID's. Also the root filesystem seems to be read-write already. It's some other filesystems mounted on various folders that are read-only. I am able to modify /etc/fstab, but the changes I make aren't persistent.
Try running the following command on the NAS system;

Code:
lsblk -f
Quote:
I think I now have my answer on the filesystems: it's not possible to make /ram_bin read-write, scroll down to the last command.
It looks like you're correct.

Quote:
Here are a few commands and corresponding outputs that I tried:

mount -o remount,rw
I'm not sure that would work, given you haven't specified which filesystem it should be mounting.

Quote:
...
mount -o remount,rw -t ext2 /dev/loop0 /ram_bin
mount: block device /dev/loop0 is write-protected, mounting read-only
If that's your NAS device, then that says it all - highlighted in bold.
 
Old 10-06-2018, 11:38 AM   #7
dr-artsi
LQ Newbie
 
Registered: Oct 2018
Posts: 7

Original Poster
Rep: Reputation: Disabled
It's a bit disappointing discovery, really...

But I'm still convinced there is a way to make it persistent. The NAS has a built-in user interface that opens with a web browser, and it is possible to make persistent changes there -- for example the SSH connection was not possible by default. A new package had to be installed through that browser interface. Also, all those modifications to the NAS settings are persistent --> There has to be some script or file or whatever somewhere that holds these changes that are made during run-time and then read during booting. That file is the place where I should add some magic line that puts in the crontab entry.

I will post an update here if I ever find that mystery-file.
 
Old 10-06-2018, 06:34 PM   #8
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
Are you using crontab, or directly editing the files?
 
Old 10-07-2018, 01:44 AM   #9
dr-artsi
LQ Newbie
 
Registered: Oct 2018
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by AwesomeMachine View Post
Are you using crontab, or directly editing the files?
My crontab entry is somethong like this:
*/15 * * * * python /path/to/file/script.py

And that entry is in the root's crontab file. It works and does everything it should, except for the persistency. Note that the script resides on the mounted 750GB hard drive, not on the NAS itself.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to make an entry in crontab through shell script called by php page Ankush Seth Linux - Newbie 28 10-08-2013 04:07 AM
about crontab entry Ravi kumar Linux - Software 2 09-16-2008 01:41 PM
Somehow not getting crontab entry right Jykke Linux - Desktop 4 02-29-2008 01:50 PM
crontab entry? Master Fox Linux - Software 4 08-23-2005 01:20 PM
crontab entry pilipk01 Linux - General 4 11-19-2003 07:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration