Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Force fsck on headless servers and remote macs' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Force fsck on headless servers and remote macs
Authored by: joelbruner on Aug 18, '10 10:36:25AM
Always a multitude of ways, so if I might chip in my 2 cents on the comments

This does something similar, except it boots to single user mode, using the .profile for root check it is single user mode, runs fsck, mounts the drive, writes the result to a file, then deletes the .profile, sure the fsck could be more elegantly redirected or tee'd but take it for what it is

#modify nvram for single user
nvram boot-args="-s"

#modify Single User mode for auto fsck -fy
echo 'if [ $HOSTNAME = localhost ] || [ -z $SECURITYSESSIONID ]; then clear; echo "Starting File System Check in 5 seconds, Control-C to quit"; /bin/sleep 6; fsckResult=$(/sbin/fsck -fy); echo "$fsckResult"; /sbin/mount -uw /; echo "$fsckResult" >> /var/log/fsck.log; /bin/rm /var/root/.profile; nvram boot-args=""; echo "Rebooting in 10 seconds."; /bin/sleep 10; /sbin/shutdown -r now; fi' > /var/root/.profile

reboot

the reboot at the end is to immediately reboot the client computer, useful for sending via ARD, but be careful all commands must be run as root of course :)

[ Reply to This | # ]
Force fsck on headless servers and remote macs
Authored by: ernst_mulder on Aug 19, '10 12:07:56AM

Your (nice btw) method is missing a "touch /var/log/fsck.log". Appending to /var/log/fsck.log using >> will result in an error if /var/log/fsck.log does not exist.



[ Reply to This | # ]
Force fsck on headless servers and remote macs
Authored by: zeniam1 on Aug 19, '10 09:33:51AM
Since when?

% ls -l foobar
ls: foobar: No such file or directory
% echo 'hello' >> foobar
% ls -l foobar
-rw-r--r--  1 howes  staff  6 Aug 19 12:32 foobar
%


[ Reply to This | # ]
Force fsck on headless servers and remote macs
Authored by: chuckadile on Oct 03, '12 01:35:50PM

I have found this extremely useful. I want to write this into an applescript that can run on a local machine like this:

tell application "Terminal" to do shell script "sudo echo 'if [ $HOSTNAME = localhost ] || [ -z $SECURITYSESSIONID ]; then clear; echo "Checking File System. The Computer will reboot in 1 minute..."; /bin/sleep 6; fsckResult=$(/sbin/fsck -fy); echo "$fsckResult"; /sbin/mount -uw /; echo "$fsckResult" >> /var/log/fsck.log; /bin/rm /var/root/.profile;cd /Library/Preferences; plutil -s *.plist; rm `plutil -s *.plist | grep "plist:" | sed "s/://g"`; nvram boot-args=""; echo "Rebooting in 10 seconds."; /bin/sleep 10; /sbin/shutdown -r now; fi' > /var/root/.profile " with administrator privileges

However since the whole command needs to be inside quotations the the quotations inside the command prevent it from compiling
I have gotten this to work:

tell application "Terminal" to do shell script "sudo echo 'if [ $HOSTNAME = localhost ] || [ -z $SECURITYSESSIONID ]; then clear; /bin/sleep 6; fsckResult=$(/sbin/fsck -fy); /sbin/mount -uw /;/var/log/fsck.log; /bin/rm /var/root/.profile; nvram boot-args=; /bin/sleep 10; /sbin/shutdown -r now; fi' > /var/root/.profile " with administrator privileges

But not as nice without messages to let the user know what's going on.

Any suggestions?



[ Reply to This | # ]