Want to schedule delete files and folders on attached USB drive.

Introduce yourself to us and other members here, or share your own product reviews, suggestions, and tips and tricks of using QNAP products.
Locked
User avatar
OneCD
Guru
Posts: 12143
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: Want to schedule delete files and folders on attached USB drive.

Post by OneCD »

Spider99 wrote:and its running twice!
I know, i know... a step has been missed. And another step has been done twice. ;)

Just waiting on an answer to my last question before addressing that.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
sharper9
Know my way around
Posts: 196
Joined: Fri Jun 06, 2008 6:10 pm

Re: Want to schedule delete files and folders on attached USB drive.

Post by sharper9 »

OneCD wrote:Can you please advise as to whether you ran delete-old-stuff.sh successfully? I do need to know if it worked before moving forward. ;)
Yes I did run it as you directed....with no errors

BUT

Had a 'drive full error' last night, so stupidly 'manually' deleted it over breakfast this morning :x

I THEN ran delete-old-stuff.sh as I said with no errors. AND the rest of your instructions, sent last from you.


So dont/will not know if it worked till the backup finishes which I started manually a moment ago.

Im having trouble copying the code from nano.
I keep getting spurious lines at the bottom?

I use crt + x to quit nano.

But copy? is the problem :oops:

I highlight the text with mouse or arrow keys but copy goes haywire I think


The double entry was done about an hour ago in response to you post "Tue Mar 14, 2017 4:58 pm"
All the best

TS251A 8GB 2 x 3TB JBOD for LMS and loads of other stuff. 2 Hikvision DS-2CD2342WD-I
Firmware 4.4.3.1354 - Windows 11 + 2 x iPads
User avatar
OneCD
Guru
Posts: 12143
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: Want to schedule delete files and folders on attached USB drive.

Post by OneCD »

sharper9 wrote:
OneCD wrote:Can you please advise as to whether you ran delete-old-stuff.sh successfully? I do need to know if it worked before moving forward. ;)
Yes I did run it as you directed....with no errors
I should have been clearer - what I meant is that after it ran, did you check that it had only deleted files and folders older than 11 days?
sharper9 wrote:Im having trouble copying the code from nano.
I keep getting spurious line at the bottom?
No, you won't need to copy from nano. It's the editor.





As I think there may be some confusion over what is required, I need to give you a short series of things to do. These must be carried out in order. If you don't see something that looks the same as here - then STOP and post back. Don't skip steps and don't do each step more than once. ;)



  1. Edit your crontab file and ensure you only have one copy of delete-old-stuff.sh listed:

    Code: Select all

    nano /etc/config/crontab
    Your crontab file should look like this:
    # m h dom m dow cmd
    0 3 * * 0 /etc/init.d/idmap.sh dump
    0 4 * * * /sbin/hwclock -s
    0 3 * * * /sbin/vs_refresh
    0 3 * * * /sbin/clean_reset_pwd
    0-59/15 * * * * /etc/init.d/nss2_dusg.sh
    30 7 * * * /sbin/clean_upload_file
    0 2 * * * /sbin/qfstrim
    0-59/10 * * * * /etc/init.d/storage_usage.sh
    30 3 * * * /sbin/notice_log_tool -v -R
    31 * * * * /sbin/qddns_check 2>/dev/null
    10 15 * * * /usr/bin/power_clean -c 2>/dev/null
    10 0 * * * /etc/init.d/antivirus.sh scan 1
    0 0 * * * /etc/init.d/antivirus.sh archive_log
    08 0 */1 * * /etc/init.d/antivirus.sh update_db
    * * * * * /mnt/ext/opt/netmgr/util/lock_timer.sh
    35 7 * * * /sbin/qbox_util -c > /dev/null 2>/dev/null
    4 3 * * 3 /etc/init.d/backup_conf.sh
    0 1 * * * /share/50014EE20BA4E444_DATA/.system/delete-old-stuff.sh
  2. Ensure the last line of the file is empty,
  3. Save and exit the nano editor,
  4. Check that the crontab file is correct:

    Code: Select all

    cat /etc/config/crontab
    You should see your single line that calls delete-old-stuff.sh at the bottom.
  5. Please post this screen back here along with the command you used to show this file (cat).
  6. Load your crontab file:

    Code: Select all

    crontab /etc/config/crontab
  7. Restart the cron daemon:

    Code: Select all

    /etc/init.d/crond.sh restart
  8. Confirm that your new crontab file has been loaded by the cron daemon:

    Code: Select all

    crontab -l
  9. Please post this screen back here along with the command you used to show this file (crontab).

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
OneCD
Guru
Posts: 12143
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: Want to schedule delete files and folders on attached USB drive.

Post by OneCD »

sharper9 wrote:The double entry was done about an hour ago in response to you post "Tue Mar 14, 2017 4:58 pm"
In that post, I asked whether you had edited the file. I didn't say to edit it again. I was quite literal. ;)

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
sharper9
Know my way around
Posts: 196
Joined: Fri Jun 06, 2008 6:10 pm

Re: Want to schedule delete files and folders on attached USB drive.

Post by sharper9 »

Sorry to muck you about.

I'll do this in the morning and post back.
I think we are 'nearly' there.

Thx
All the best

TS251A 8GB 2 x 3TB JBOD for LMS and loads of other stuff. 2 Hikvision DS-2CD2342WD-I
Firmware 4.4.3.1354 - Windows 11 + 2 x iPads
User avatar
sharper9
Know my way around
Posts: 196
Joined: Fri Jun 06, 2008 6:10 pm

Re: Want to schedule delete files and folders on attached USB drive.

Post by sharper9 »

OneCD wrote:
sharper9 wrote:The double entry was done about an hour ago in response to you post "Tue Mar 14, 2017 4:58 pm"
In that post, I asked whether you had edited the file. I didn't say to edit it again. I was quite literal. ;)
I doubled because I thought I had 'not' done it correctly. So I did it again this it was doubled.

Anyway till tomorrow
Last edited by sharper9 on Wed Mar 15, 2017 3:04 am, edited 2 times in total.
All the best

TS251A 8GB 2 x 3TB JBOD for LMS and loads of other stuff. 2 Hikvision DS-2CD2342WD-I
Firmware 4.4.3.1354 - Windows 11 + 2 x iPads
User avatar
OneCD
Guru
Posts: 12143
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: Want to schedule delete files and folders on attached USB drive.

Post by OneCD »

sharper9 wrote:I'll do this in the morning and post back.
I think we are 'nearly' there.
We are nearly there. You're doing fine. :D

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
sharper9
Know my way around
Posts: 196
Joined: Fri Jun 06, 2008 6:10 pm

Re: Want to schedule delete files and folders on attached USB drive.

Post by sharper9 »

OneCD wrote:
sharper9 wrote:I'll do this in the morning and post back.
I think we are 'nearly' there.
We are nearly there. You're doing fine. :D
Question: how do you cut and paste from nano?

So you can past it here like above?
All the best

TS251A 8GB 2 x 3TB JBOD for LMS and loads of other stuff. 2 Hikvision DS-2CD2342WD-I
Firmware 4.4.3.1354 - Windows 11 + 2 x iPads
User avatar
OneCD
Guru
Posts: 12143
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: Want to schedule delete files and folders on attached USB drive.

Post by OneCD »

sharper9 wrote:Question: how do you cut and paste from nano?

So you can past it here like above?
'nano' is only the command line editor. For what we're doing here, it's not a good idea to copy and paste from the editor, as I won't know if what I'm seeing is really in the file you're editing.

Example: you may type something while editing the file, and while still in nano, copy and paste it here. Then when you exit nano, your changes are not saved to disk for some reason. From my end, I'll think you have made changes, but in reality, those changes have been discarded.

So, it's better to edit a file, quit the editor & save your changes to disk, then use the 'cat' command to show the contents of that file on-disk.

As for copying and pasting what you view within your PuTTY terminal screen, click and drag with the mouse to select the text you want, then right-mouse-click and choose 'copy'. I don't use PuTTY (as I don't use Windows), so I'm guessing that is what's required to do this. You've done it before so you already know this. ;)

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
sharper9
Know my way around
Posts: 196
Joined: Fri Jun 06, 2008 6:10 pm

Re: Want to schedule delete files and folders on attached USB drive.

Post by sharper9 »

OneCD wrote:Please post this screen back here along with the command you used to show this file (cat).

Code: Select all

[~] # cat /etc/config/crontab
# m h dom m dow cmd
0 3 * * 0 /etc/init.d/idmap.sh dump
0 4 * * * /sbin/hwclock -s
0 3 * * * /sbin/vs_refresh
0 3 * * * /sbin/clean_reset_pwd
0-59/15 * * * * /etc/init.d/nss2_dusg.sh
30 7 * * * /sbin/clean_upload_file
0 2 * * * /sbin/qfstrim
0-59/10 * * * * /etc/init.d/storage_usage.sh
30 3 * * * /sbin/notice_log_tool -v -R
31 * * * * /sbin/qddns_check 2>/dev/null
10 15 * * * /usr/bin/power_clean -c 2>/dev/null
10 0 * * * /etc/init.d/antivirus.sh scan 1
0 0 * * * /etc/init.d/antivirus.sh archive_log
08 0 */1 * * /etc/init.d/antivirus.sh update_db
* * * * * /mnt/ext/opt/netmgr/util/lock_timer.sh
35 7 * * * /sbin/qbox_util -c  > /dev/null 2>/dev/null
0 1 * * * /share/50014EE20BA4E444_DATA/.system/delete-old-stuff.sh

OneCD wrote:Please post this screen back here along with the command you used to show this file (crontab).

Code: Select all

[~] # crontab -l
# m h dom m dow cmd
0 3 * * 0 /etc/init.d/idmap.sh dump
0 4 * * * /sbin/hwclock -s
0 3 * * * /sbin/vs_refresh
0 3 * * * /sbin/clean_reset_pwd
0-59/15 * * * * /etc/init.d/nss2_dusg.sh
30 7 * * * /sbin/clean_upload_file
0 2 * * * /sbin/qfstrim
0-59/10 * * * * /etc/init.d/storage_usage.sh
30 3 * * * /sbin/notice_log_tool -v -R
31 * * * * /sbin/qddns_check 2>/dev/null
10 15 * * * /usr/bin/power_clean -c 2>/dev/null
10 0 * * * /etc/init.d/antivirus.sh scan 1
0 0 * * * /etc/init.d/antivirus.sh archive_log
08 0 */1 * * /etc/init.d/antivirus.sh update_db
* * * * * /mnt/ext/opt/netmgr/util/lock_timer.sh
35 7 * * * /sbin/qbox_util -c  > /dev/null 2>/dev/null
0 1 * * * /share/50014EE20BA4E444_DATA/.system/delete-old-stuff.sh
All the best

TS251A 8GB 2 x 3TB JBOD for LMS and loads of other stuff. 2 Hikvision DS-2CD2342WD-I
Firmware 4.4.3.1354 - Windows 11 + 2 x iPads
User avatar
OneCD
Guru
Posts: 12143
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: Want to schedule delete files and folders on attached USB drive.

Post by OneCD »

And ... you're done! :DD

Your crontab looks great. All that's left to do is monitor that USB drive and periodically check that those files are being deleted. You can add further paths to the bottom of delete-old-stuff.sh as needed.

If you have any further questions, or are unsure as to how to alter the schedule, please post back and I'd be happy to assist.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
sharper9
Know my way around
Posts: 196
Joined: Fri Jun 06, 2008 6:10 pm

Re: Want to schedule delete files and folders on attached USB drive.

Post by sharper9 »

OneCD wrote:And ... you're done! :DD

Your crontab looks great. All that's left to do is monitor that USB drive and periodically check that those files are being deleted. You can add further paths to the bottom of delete-old-stuff.sh as needed.

If you have any further questions, or are unsure as to how to alter the schedule, please post back and I'd be happy to assist.
Many many thanks, you are a star!
All the best

TS251A 8GB 2 x 3TB JBOD for LMS and loads of other stuff. 2 Hikvision DS-2CD2342WD-I
Firmware 4.4.3.1354 - Windows 11 + 2 x iPads
User avatar
sharper9
Know my way around
Posts: 196
Joined: Fri Jun 06, 2008 6:10 pm

Re: Want to schedule delete files and folders on attached USB drive.

Post by sharper9 »

Sadly it does not look like its deleted the files
I changed the crontab to fire @ 11 (see below).

Then I Loaded crontab file:
crontab /etc/config/crontab

Restarted the cron daemon:
/etc/init.d/crond.sh restart

Confirmed that your new crontab file has been loaded by the cron daemon: (Not sure what this tell me :ashamed: )
crontab -l

# m h dom m dow cmd
0 3 * * 0 /etc/init.d/idmap.sh dump
0 4 * * * /sbin/hwclock -s
0 3 * * * /sbin/vs_refresh
0 3 * * * /sbin/clean_reset_pwd
0-59/15 * * * * /etc/init.d/nss2_dusg.sh
30 7 * * * /sbin/clean_upload_file
0 2 * * * /sbin/qfstrim
0-59/10 * * * * /etc/init.d/storage_usage.sh
30 3 * * * /sbin/notice_log_tool -v -R
31 * * * * /sbin/qddns_check 2>/dev/null
10 15 * * * /usr/bin/power_clean -c 2>/dev/null
10 0 * * * /etc/init.d/antivirus.sh scan 1
0 0 * * * /etc/init.d/antivirus.sh archive_log
08 0 */1 * * /etc/init.d/antivirus.sh update_db
* * * * * /mnt/ext/opt/netmgr/util/lock_timer.sh
35 7 * * * /sbin/qbox_util -c > /dev/null 2>/dev/null
0 11 * * * /share/50014EE20BA4E444_DATA/.system/delete-old-stuff.sh
4 3 * * 3 /etc/init.d/backup_conf.sh

Then once again I noticed the last SOB! :evil: line keeps appearing.

What, in my clumsy way, I was trying to achieve was to test/run the delete job. I failed!

Help! once again
All the best

TS251A 8GB 2 x 3TB JBOD for LMS and loads of other stuff. 2 Hikvision DS-2CD2342WD-I
Firmware 4.4.3.1354 - Windows 11 + 2 x iPads
User avatar
OneCD
Guru
Posts: 12143
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: Want to schedule delete files and folders on attached USB drive.

Post by OneCD »

sharper9 wrote:Sadly it does not look like its deleted the files
I changed the crontab to fire @ 11 (see below).
Looks good. That should run it at 11am, each day. :)
sharper9 wrote:Then once again I noticed the last SOB! :evil: line keeps appearing.
That's OK. The order can be changed by the NAS - it edits this file too.

And the actual order of scheduled items (in this file) doesn't matter. ;)
sharper9 wrote:What, in my clumsy way, I was trying to achieve was to test/run the delete job. I failed!
To run the script manually:

Code: Select all

/share/50014EE20BA4E444_DATA/.system/delete-old-stuff.sh

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
sharper9
Know my way around
Posts: 196
Joined: Fri Jun 06, 2008 6:10 pm

Re: Want to schedule delete files and folders on attached USB drive.

Post by sharper9 »

To run the script manually:

Code: Select all

/share/50014EE20BA4E444_DATA/.system/delete-old-stuff.sh

This lists the files OK, but does not delete them?
All the best

TS251A 8GB 2 x 3TB JBOD for LMS and loads of other stuff. 2 Hikvision DS-2CD2342WD-I
Firmware 4.4.3.1354 - Windows 11 + 2 x iPads
Locked

Return to “Users' Corner”