-
-
Save rlemon/66c8fcdb07f408b0608a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sys = require('sys') | |
var exec = require('child_process').exec; | |
var fs = require('fs'); | |
var filepath = "/home/root/count.txt"; | |
read(); | |
function read() { | |
fs.readFile(filepath, function( err, data ) { | |
if( err ) { | |
console.log( "read error" , err ); | |
return; | |
} | |
write(parseInt(data.toString(), 10)); | |
}); | |
} | |
function write(count) { | |
fs.writeFile(filepath, count+1, function(err) { | |
if( err ) { | |
console.log( "read error" , err ); | |
return; | |
} | |
shutdown(); | |
} | |
} | |
function shutdown() { | |
exec("shutdown -r now", function puts(error, stdout, stderr) { | |
console.log( stdout, stderr ); | |
sys.puts(stdout); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment