LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Need help to write script for crontab Hdd operation (https://www.linuxquestions.org/questions/slackware-14/need-help-to-write-script-for-crontab-hdd-operation-852937/)

kapz 12-28-2010 10:01 PM

Need help to write script for crontab Hdd operation
 
Hi,

I have this Maxtor USB external HDD which I mount via dolphin-hal when needed. This HDD has a built in feature to 'sleep' if not used for some time, say 20 min. Now I don't want it to sleep because it irritates me to wait everytime for it to be active for use, so I figured crontab job should fulfill my requirement.

*Edit: I think a script needs to be executed every 15 minutes. The script has to do the following(I think):

Check to see if HDD is conected via USB:
If YES then - Do the below things
If NO - Do nothing

"Below Things":

Check if the ext4 fs is mounted on media/Maxtor-C; if yes then check if any file operation is being performed; if yes-do nothing, if no then write and remove an empty file.
if hdd is connected but not mounted then hdparm -z /dev/sdxx (read partitions)

Can anyone please suggest a script?

Thanks a lot.

catkin 12-29-2010 04:43 AM

What have you tried so far?

Martinezio 12-29-2010 05:42 AM

What help You need: to test if the disk is connected, or to make some proc with the disk to make it no sleep?

The first one is the easy pie, if You know the mount point:
Code:

#!/bin/bash

test=`df | grep -c /media/USBDRIVE`

if [ $test -eq "1" ]
then
    echo "Drive is connected"
else
    echo "Drive is not connected"
fi

The second part should be also easy. You need to touch particular file on that drive (ie. some random named file, but first check if it not exists), and next delete them after short period of time. This will ensure, that this command will be commited from the drive internal buffers.

Good luck.

mRgOBLIN 12-29-2010 06:02 AM

A simple `fdisk -l` should wake up any connected drive regardless of whether it's mounted or not.

kapz 12-29-2010 06:33 AM

Thanks a lot guys :)

Quote:

What have you tried so far?
Never wrote any script before,but I was looking at rc.S and trying to figure out a way to use this for my script:
Code:

READWRITE=no
if touch /fsrwtestfile 2>/dev/null; then
  rm -f /fsrwtestfile
  READWRITE=yes
fi

but couldn't think of anything to check if drive was connected via USB.


Quote:

What help You need: to test if the disk is connected, or to make some proc with the disk to make it no sleep?
I want my drive to not sleep automatically. I could only think of creating and deleting an empty file every 15 minutes but couldn't figure out how to put them in if, else loop and create a bash script.

Quote:

A simple `fdisk -l` should wake up any connected drive regardless of whether it's mounted or not.
Thanks mRgOBLIN, that is indeed the smart solution..now if I set up a cron job to do that every 15 minutes and then if I start a file copy operation of say 10 GB then while the operation is in progress and at the same time the cron initiates fdisk -l, will it create any problem?

*Edit* Alright I tried it manually and it didn't create any problem, both cp and fdisk -l carried out successfully simultaneously.
Still I'd like to know what you think.

Martinezio 12-29-2010 06:54 AM

It should be safe. This command is just to read the partition table from the drive without any write operations.
But I wondering, if processing this command prevent the drive from sleep... Partition table should stay cached in drives internal buffers just after startup and is not rereaded every list command is triggered... But this should be put in confrontation with drive's manual, or service book... If it is reachable ;)

kapz 12-29-2010 09:34 PM

Works fine even after reboot(s). Marking as solved.

JZL240I-U 01-05-2011 07:42 AM

If the drive accepts IDE / ATA commands
Code:

hdparm -S0 /dev/<your-device-here>
http://linux.die.net/man/8/hdparm


All times are GMT -5. The time now is 10:44 AM.