LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-03-2012, 01:30 AM   #1
Hailey's_Comet
Member
 
Registered: Jul 2005
Location: USA
Distribution: PCLinuxOS
Posts: 36

Rep: Reputation: 18
script for samba to run to shutdown server?


I have a samba share called "shutdown". I want to write a script that is run when that share is logged into that will shutdown my server. I regularly view movies using my xbox and don't want to have to walk into my living room to shutdown my server. (RPC stuff from client is not an option)

sys specs:
Debian Squeeze
samba 3.5.6

No matter what bash script I write, I can't get it done. Can someone help me?
 
Old 10-03-2012, 01:48 AM   #2
fortran
Member
 
Registered: Nov 2011
Location: Cairo, Egypt
Distribution: CentOS, RHEL, Fedora
Posts: 300
Blog Entries: 2

Rep: Reputation: 51
Why don't you use ssh to shutdown server. It is quite easy.
 
Old 10-03-2012, 02:21 AM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by pavi_kanetkar View Post
Why don't you use ssh to shutdown server. It is quite easy.
Because there are no good SSH clients for the Xbox.

@Hailey's_Comet: You don't even need a separate share for this. Copy a small mp3 file to your normal share and call it shutdown.mp3, so that you can open it with the Xbox. Now you can use inotify to wait for that file to be opened by you and use that event to shutdown the system.
 
Old 10-03-2012, 01:00 PM   #4
Hailey's_Comet
Member
 
Registered: Jul 2005
Location: USA
Distribution: PCLinuxOS
Posts: 36

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by pavi_kanetkar View Post
Why don't you use ssh to shutdown server. It is quite easy.
Because I am trying to get this done with the ability to use ANYTHING that can access a simple samba share. I am currently writing this from a laptop logged into my server with XDMCP tunneled in SSH, which is beyond mere SSH. I have a myriad of means already, I just want one more.

Besides, if I can get it done it will be the end to a long project.
 
Old 10-03-2012, 01:10 PM   #5
Hailey's_Comet
Member
 
Registered: Jul 2005
Location: USA
Distribution: PCLinuxOS
Posts: 36

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by TobiSGD View Post
Because there are no good SSH clients for the Xbox.

@Hailey's_Comet: You don't even need a separate share for this. Copy a small mp3 file to your normal share and call it shutdown.mp3, so that you can open it with the Xbox. Now you can use inotify to wait for that file to be opened by you and use that event to shutdown the system.
"inotify" would be lovely, I will make a utility from example code from http://www.thegeekstuff.com/2010/04/...ogram-example/. I would, however, like a bash script alternative to make it more portable.
 
Old 10-03-2012, 01:28 PM   #6
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Code:
inotifywait -e access /path/to/the/monitored/file
will wait for the file to be accessed and return with exit-code 0 if the event occurs. So a script like this
Code:
#!/bin/bash
inotifywait -e access /path/to/the/monitored
if (( $? > 0 )) then
    echo "An error occurred with inotifywait" >> logfile
    exit 1
else
    echo "Received access event from inotifywait" >> logfile
    /sbin/poweroff &
fi
exit 0
should work.
 
1 members found this post helpful.
Old 10-04-2012, 11:01 AM   #7
Hailey's_Comet
Member
 
Registered: Jul 2005
Location: USA
Distribution: PCLinuxOS
Posts: 36

Original Poster
Rep: Reputation: 18
@TobiSGD, where were you 5 years ago when I was originally looking for this solution? Thanks for the elegant solution!

EDIT: on Debian (and possibly others) this [is|may be] in the inotify-tools package.

Last edited by Hailey's_Comet; 10-04-2012 at 11:06 AM.
 
Old 10-04-2012, 11:41 AM   #8
Hailey's_Comet
Member
 
Registered: Jul 2005
Location: USA
Distribution: PCLinuxOS
Posts: 36

Original Poster
Rep: Reputation: 18
To make it end-user configurable for multiple monitoring, I will be making a script that will be callable with args from init scripts, but for now this is what I am using (unconfigured state):
Code:
#!/bin/bash
monitor="/path/to/shared/dir"
logfile="/var/log/samba/smbshutdown.log"
success="Recieved shutdown command via samba"
failure="An error occurred with smbshutdown->inotifywait"
cmd="/sbin/poweroff &"

inotifywait -e access "$monitor"
if (( $? > 0 )) then
    _date=`date`
    echo "$failure @ $_date" >> "$logfile"
    exit 1
else
    _date=`date`
    echo "$success @ $_date" >> "$logfile"
    $cmd
fi
exit 0
When I am done, I will post it to bashscripts.org so I don't lose it!


.
 
  


Reply



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
UBUNTU: can I run startup script only (not on shutdown)? fopetesl Linux - Software 8 06-10-2010 03:16 AM
Getting an /etc/init.d script to run at system shutdown forrie Linux - Server 6 05-05-2010 01:19 PM
init script does not run at the shutdown time procfs Linux - Newbie 4 02-16-2010 02:00 AM
Run script on shutdown or reboot VeeDubbs Linux - Server 1 10-23-2008 01:34 PM
How to run a script at startup after a shutdown? kklein9 Linux - Software 3 01-27-2006 03:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:02 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
Open Source Consulting | Domain Registration