Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[solved] mount in script nutzen
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum
View previous topic :: View next topic  
Author Message
Moorenkopf
Apprentice
Apprentice


Joined: 18 Apr 2004
Posts: 189
Location: NRW

PostPosted: Sat Aug 19, 2006 3:02 pm    Post subject: [solved] mount in script nutzen Reply with quote

Hi,

ich habe einen Cronjob für updatedb eingerichtet: 0 0,14 * * * nice -19 /usr/bin/updatedb
Jetzt möchte ich aber sicherstellen, dass /dev/hdb4 währenddessen (wie in der fstab eingetragen) in /mnt/hd eingebunden ist.

Also dachte ich an
Code:
mount /mnt/hd && nice -19 /usr/bin/updatedb
. Das funktioniert aber nur, wenn /mnt/hd nicht schon vorher eingebunden ist.

Hat jemand einen Tipp, wie ich das überprüfen kann? /mnt/hd vorher aushängen möchte ich natürlich nicht.


Gruß Stefan


PS: Wer mitdenkt wird merken, dass ich /mnt/hd, wenn es vorher nicht gemounted war, hinterher auch wieder aushängen möchte :)


Last edited by Moorenkopf on Mon Aug 21, 2006 10:09 am; edited 1 time in total
Back to top
View user's profile Send private message
franzf
Advocate
Advocate


Joined: 29 Mar 2005
Posts: 4565

PostPosted: Sat Aug 19, 2006 3:10 pm    Post subject: Reply with quote

Erstell dir ein eigenes Script: myupdatedb (oder so ;))
Das legst du dann anstelle von updatedb in den cron.
Nun kannst du in mount (ohne Parameter zeigt es die aktuell gemounteten Partitionen an) rumgreppen ob schon eingehängt. Falls nein -> mounten, sonst ->updatedb
Aber das ganze drumherum kannst schon selber ;) ist net so schwer.
Code:
man bash
man grep
man mount


Viel Erfolg ;)
Franz
Back to top
View user's profile Send private message
Moorenkopf
Apprentice
Apprentice


Joined: 18 Apr 2004
Posts: 189
Location: NRW

PostPosted: Sat Aug 19, 2006 4:48 pm    Post subject: Reply with quote

Danke, ich hab's gleich mal versucht:
Code:
#!/bin/bash
# HDB4 shows weather /dev/hdb4 is mounted or not (1/0)
HDB4=1
# FALSE shows weather updatedb failed or not (1/0)
FALSE=0

# umount /mnt/hd, if neccessary, and exit
end () {
        if [ $HDB4 -eq "0" ];
        then
                umount /mnt/hd &> /dev/null || echo "failed to umount /mnt/hd" && exit -1;
        fi

        if [ $FALSE -ge "0" ];
        then
                echo "failed to updatedb" && exit -1;
        fi
}


mount | grep "/dev/hdb4 on /mnt/hd" &> /dev/null || HDB4=0;

if [ $HDB4 -eq "0" ];
then
        mount /dev/hdb4 /mnt/hd &> /dev/null || echo "failed to mount /dev/hdb4 /mnt/hd" && exit -1;
fi

nice -19 /usr/bin/updatedb &> /dev/null || false=1 && end
end


Wenn /dev/hdb4 vorher nicht schon gemounted ist, scheint's zu funktionieren, sonst aber nicht.
Wäre nett, wenn ihr da mal drüber gucken könntet.

Gruß Stefan
Back to top
View user's profile Send private message
Fabiolla
Apprentice
Apprentice


Joined: 04 Mar 2004
Posts: 277
Location: somewhere

PostPosted: Sat Aug 19, 2006 6:13 pm    Post subject: Reply with quote

Hallo,

So wie ich das Script verstehe fehlt da irgndwie die Abfrage auf den Rückgabewert von grep.
Code:

mount | grep "/dev/hdb4 on /mnt/hd" &> /dev/null || HDB4=0;


Folgendes sollte funktionieren (die If-Abfrage sollte noch optimiert werden, grep kann auch 2 zurückliefern)
Code:

mount | grep "/dev/hdb4 on /mnt/hd" &> /dev/null; return=$?

if [ $return -eq 1 ]; then
    mount /dev/hdb4 /mnt/hd &> /dev/null || echo "failed to mount /dev/hdb4 /mnt/hd" && exit -1;
else
   echo "Ist bereits gemountet"
fi
Back to top
View user's profile Send private message
firefly
Watchman
Watchman


Joined: 31 Oct 2002
Posts: 5329

PostPosted: Sat Aug 19, 2006 6:16 pm    Post subject: Reply with quote

Quote:
nice -19 /usr/bin/updatedb &> /dev/null || false=1 && end

sollte das "false" nicht "FALSE" heißen? vorrausgesetzt du möchtest hier die variable FALSE auf 1 setzen
_________________
Ein Ring, sie zu knechten, sie alle zu finden,
Ins Dunkel zu treiben und ewig zu binden
Im Lande Mordor, wo die Schatten drohn.
Back to top
View user's profile Send private message
76062563
l33t
l33t


Joined: 16 Aug 2004
Posts: 637
Location: 127.0.0.1

PostPosted: Sun Aug 20, 2006 12:24 am    Post subject: Reply with quote

Moorenkopf wrote:
...
# HDB4 shows weather /dev/hdb4 is mounted or not (1/0)
HDB4=1
# FALSE shows weather updatedb failed or not (1/0)
...

Und was machst du wenns regnet?
_________________
gentoo - compile your own world
Back to top
View user's profile Send private message
STiGMaTa_ch
Veteran
Veteran


Joined: 28 Dec 2004
Posts: 1686
Location: Rüti ZH / Schweiz

PostPosted: Sun Aug 20, 2006 8:59 am    Post subject: Re: mount in script nutzen Reply with quote

Moorenkopf wrote:
Das funktioniert aber nur, wenn /mnt/hd nicht schon vorher eingebunden ist.

Hat jemand einen Tipp, wie ich das überprüfen kann? /mnt/hd vorher aushängen möchte ich natürlich nicht.



Code:
[ ! "`mount |grep /dev/hdb4`" = "" ] && echo "hdb4 ist bereits gemountet" || mount /dev/hdb4 /mnt/hd

Und falls du keine Textausgabe willst bei bereits gemounteter HD4:

Code:
[ "`mount |grep /dev/hda8`" = "" ] && mount /dev/hdb4 /mnt/hd


Lieber Gruss
STiGMaTa
_________________
Ich bin Schuldknappe. Das bedeutet ich bin immer an allem Schuld. Und das nicht zu knapp! | Der alltägliche Familienwahnsinn auf meinem BLOG
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Sun Aug 20, 2006 9:31 am    Post subject: Re: mount in script nutzen Reply with quote

Moorenkopf wrote:
Also dachte ich an
Code:
mount /mnt/hd && nice -19 /usr/bin/updatedb
. Das funktioniert aber nur, wenn /mnt/hd nicht schon vorher eingebunden ist.
Hat jemand einen Tipp, wie ich das überprüfen kann? /mnt/hd vorher aushängen möchte ich natürlich nicht.

Code:
[ "`grep -s /mnt/hd /etc/mtab`" ] || mount /mnt/hd

_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
Moorenkopf
Apprentice
Apprentice


Joined: 18 Apr 2004
Posts: 189
Location: NRW

PostPosted: Sun Aug 20, 2006 11:25 am    Post subject: Reply with quote

Hallo zusammen

Fabiolla wrote:
So wie ich das Script verstehe fehlt da irgndwie die Abfrage auf den Rückgabewert von grep.
Code:

mount | grep "/dev/hdb4 on /mnt/hd" &> /dev/null || HDB4=0;

Ich hatte mir überlegt HDB4 auf 0 zu setzen, wenn grep nichts findet, weil ich mir nicht anders zu helfen wusste. Das werd ich aber umändern.

76062563 wrote:
Und was machst du wenns regnet?

Dann guck ich mal ins Wörterbuch und stelle fest, dass ich die beiden Wörter immernoch dauernd verwechsle :)

firefly wrote:
sollte das "false" nicht "FALSE" heißen? vorrausgesetzt du möchtest hier die variable FALSE auf 1 setzen

Richtig, war so geplant.

Ich muss jetzt zur Arbeit, aber das Script dürfte kein Problem mehr sein, danke.

Gruß Stefan

Edit:
Code:
#!/bin/bash
MOUNT=0
[ "`grep -s /dev/hdb4 /mnt/hd /etc/mtab`" ] && MOUNT=1

# mount /mnt/hd if neccessary
if [ $MOUNT -eq 0 ];
then
   mount /mnt/hd &> /dev/null;
   if [ $? -ne 0 ];
        then
                echo "myupdatedb.sh: failed to mount /mnt/hd" | mail -s "`hostname --fqdn`: myupdatedb.sh" root
                exit -1;
        fi
fi

#updatedb
nice -19 /usr/bin/updatedb &> /dev/null
if [ $? -ne 0 ];
then
        echo "myupdatedb.sh: failed to exec /usr/bin/updatedb" | mail -s "`hostname --fqdn`: myupdatedb.sh" root
fi

# umount /mnt/hd if neccessary
if [ $MOUNT -eq 0 ];
then
   umount /mnt/hd &> /dev/null;
fi
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum