LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 12-28-2010, 10:01 PM   #1
kapz
Member
 
Registered: Mar 2009
Location: kernel space
Distribution: Slackware_x64
Posts: 191

Rep: Reputation: 16
Post 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.

Last edited by kapz; 12-29-2010 at 01:07 AM.
 
Old 12-29-2010, 04:43 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196
What have you tried so far?
 
Old 12-29-2010, 05:42 AM   #3
Martinezio
Member
 
Registered: May 2009
Location: Warsaw, Poland
Distribution: Slackware64-current
Posts: 191

Rep: Reputation: 32
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.
 
Old 12-29-2010, 06:02 AM   #4
mRgOBLIN
Slackware Contributor
 
Registered: Jun 2002
Location: New Zealand
Distribution: Slackware
Posts: 999

Rep: Reputation: 229Reputation: 229Reputation: 229
A simple `fdisk -l` should wake up any connected drive regardless of whether it's mounted or not.
 
Old 12-29-2010, 06:33 AM   #5
kapz
Member
 
Registered: Mar 2009
Location: kernel space
Distribution: Slackware_x64
Posts: 191

Original Poster
Rep: Reputation: 16
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.

Last edited by kapz; 12-29-2010 at 06:52 AM.
 
Old 12-29-2010, 06:54 AM   #6
Martinezio
Member
 
Registered: May 2009
Location: Warsaw, Poland
Distribution: Slackware64-current
Posts: 191

Rep: Reputation: 32
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
 
Old 12-29-2010, 09:34 PM   #7
kapz
Member
 
Registered: Mar 2009
Location: kernel space
Distribution: Slackware_x64
Posts: 191

Original Poster
Rep: Reputation: 16
Works fine even after reboot(s). Marking as solved.
 
Old 01-05-2011, 07:42 AM   #8
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 18.3+19.0, MX-18
Posts: 4,251

Rep: Reputation: Disabled
If the drive accepts IDE / ATA commands
Code:
hdparm -S0 /dev/<your-device-here>
http://linux.die.net/man/8/hdparm
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to spin-up HDD using ioctl starvijay Linux - Hardware 2 05-09-2010 03:21 AM
External HDD spin down / powerdown fjanoos Linux - Hardware 1 09-21-2009 10:40 AM
setup crontab job user ust Linux - Newbie 2 07-07-2009 12:08 AM
Screen shakes/wobbles on external HDD spin-up Speng Linux - Hardware 1 01-16-2009 04:07 PM
crontab job Thulemanden Linux - Software 2 07-09-2006 06:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 11:27 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration