Requires registration of downloadable ActiveX comp from Skype web site on Windows machine.
Register with:
regsvr32 Skype4COM.dll
Make sure Skype is installed and logged in. When you run the prog the first time you are asked a
security question. You will need credit on your Skype account and it must be useable
through the network (if doing this from within a company and behind a firewall).
Copy the code from Option Explicit to bottom into a file called isalive.ebs
usage:cscript isalive.ebs <server> <phone> <interval> <mail recipient>
Returns: Writes to console. Sends a text if server goes off line. Sends an email also
with contents of a log file.
Requires a batch file containing words to the affect:
tracert -d %1 >> c:\diags.txt
echo "Further Info:
ping server1.fdqn >>c:\diags.txt
ping server2.fqdn >>c:\diags.txt
.
Batch file must be in same dir as the vbs.
Sends a text when it comes back on-line. Code below:
Option Explicit
'skype me a text or voicemail when my server disappears off the network.
'runs on a windows platform (whatever)
'useage:
'cscript isalive.vbs 192.168.1.109 004412345678 3000 xxxxxxxxxxxx@gmail.com
'where 192.168.1.109 is the server to ping
'and 004412345678 is the number to send a message to
Dim strHost
Dim strPhoneUser
Dim fault_detected
Dim strMessage
Dim strRecipient
Dim sleeptime
Dim oSkype
Set oSkype = WScript.CreateObject("Skype4COM.Skype", "Skype_")
If Not oSkype.Client.IsRunning Then oSkype.Client.Start() End If
' Check that all arguments required have been passed.
If Wscript.Arguments.Count < 2 Then
Wscript.Echo "Arguments required" & vbCrLf
Wscript.Quit(0)
End If
strHost = Wscript.Arguments(0)
strPhoneUser=Wscript.Arguments(1)
sleeptime=3000
If (Wscript.Arguments.Count > 2) Then
sleeptime = Wscript.Arguments(2)
End If
strRecipient = ""
If (Wscript.Arguments.Count >3 ) Then
strRecipient = Wscript.Arguments(3)
End If
Wscript.Echo "Host " & strHost
Wscript.Echo "Phone " & strPhoneUser
Wscript.Echo "Recipient " & strRecipient
Wscript.Echo "sleep " & sleeptime
fault_detected = 0
do
if Ping(strHost) = True then
Wscript.Echo "Host " & strHost & " contacted"
if (fault_detected > 0) Then
strMessage= "Server " & strHost & " back on network after " & ((fault_detected * sleeptime)/1000) & " seconds"
call_contact
fault_detected = 0
End If
Else
Wscript.Echo "Host " & strHost & " could not be contacted"
fault_detected = fault_detected + 1
If (fault_detected = 1) Then
strMessage= "Server " & strHost & " missing from network"
Wscript.Echo "Contacting user on tel. no." & strPhoneUser
call_contact
do_diagnostics ' do further research then mail someone with the information
mailuser
End If
end if
WScript.sleep (3000)
loop until (1=0)
Function call_contact
Dim oSMS
Wscript.Echo "SMS : " & strMessage
Set oSkype = WScript.CreateObject("Skype4COM.Skype", "Skype_")
Set oSMS = oSkype.SendSms(strPhoneUser, strMessage)
WScript.Sleep(20000)
End Function
'Message event handler:
Public Sub Skype_SmsMessageStatusChanged(ByRef aSms, ByVal aStatus)
WScript.Echo ">Sms " & aSms.Id & " status " & aStatus & " " & oSkype.Convert.SmsMessageStatusToText(aStatus)
End Sub
'Target event handler:
Public Sub Skype_SmsTargetStatusChanged(ByRef aTarget, ByVal aStatus)
WScript.Echo ">Sms " & aTarget.Message.Id & " target " & aTarget.Number & " status " & aStatus & " " & oSkype.Convert.SmsTargetStatusToText(aStatus)
End Sub
Function Ping(strHost)
dim objPing, objRetStatus
set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address = '" & strHost & "'")
for each objRetStatus in objPing
if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
Ping = False
else
Ping = True
end if
next
End Function
Function mailuser
Wscript.Echo "Mailing user"
Dim cdoConfig
Dim sch
Dim objMessage
Set cdoConfig = CreateObject("CDO.Configuration")
sch = "http://schemas.microsoft.com/cdo/configuration/"
With cdoConfig.Fields
.Item(sch & "sendusing") = 2 ' cdoSendUsingPort
.Item(sch & "smtpserver") = "aserver.net"
.update
End With
Set objMessage = CreateObject("CDO.Message")
Set objMessage.Configuration = cdoConfig
objMessage.Subject = "Server Status for: " + StrHost
objMessage.From = "xxxx@xxxx.com"
objMessage.To = strRecipient
objMessage.TextBody = "The Server vanished from the network. Please see the attached file."
objMessage.AddAttachment "c:\diags.txt"
objMessage.Send
set cdoConfig = nothing
set objMessage = nothing
set sch = nothing
End Function
Function do_diagnostics ' creates an attachment that will be emailed. diags.bat runs a tracert on the server and pings a few
Wscript.Echo "Running further diags"
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "diags.bat " + strHost '
'WshShell.Run "command.com /k " & CommandLine 'run DOS commands
WScript.Sleep(20000)
Set WshShell= nothing
End Function
Archive for Windows
SMS via Skype when server is down (fails ping)
get logs from servers using ftp script
Reminder to self how to use automatic ftp scripts.
Useful when you have lots of logs to fetch down from lots of fti or content server.
Replace dmadmin and <password> and servername accordingly.
batch file (content server):
mkdir -p c:\logs_all_systems\server0006\install
mkdir -p c:\logs_all_systems\server0006\product\5.3\install
ftp -i -s:server0006.scr
(fti):
mkdir -p c:\logs_all_systems\server0021\install
ftp -i -s:server0021.scr
where -i is to ignore manual requests for responses from server
script file (servernnnn.scr) for content server:
open server0006.domain.net
dmadmin
<password>
bin
cd /app/documentum/dmadmin/
lcd c:\logs_all_systems\server0006
get install.log
lcd c:\logs_all_systems\server0006\install
cd /app/documentum/dmadmin/install
mget dmadmin*
cd /app/documentum/dmadmin/product/5.3/install
lcd c:\logs_all_systems\server0006\product\5.3\install
mget dmadmin*
quit
fti:
open server0021.domain.net
dmadmin
<password>
bin
lcd c:\logs_all_systems\server0021\install
cd /app/documentum/dmadmin/install
mget dmadmin*
quit
Mounting Windows volumes in Linux (In this case Centos 5)
Assuming that samba is running
Assuming that Windows has no firewall blocking
Assuming that the folder on the Windows machine is already shared for all
Assuming the hostname of the windows server is served by a DNS or in /etc/hosts then the name can be used. (If not then use the ip)
So, where dante is the Windows host and styx is a Linux server.
[root@styx /]# mkdir /mnt/everyone
[root@styx /]# chmod -R 777 /mnt/everyone
[root@styx /]# mount //dante/everyone /mnt/everyone
To automatically mount the volume then it would be a good idea to add a line to /etc/fstab
At the end of the file (which I first made a temporary copy of)
//dante/everyone /mnt/dante/everyone cifs password=
Once saved then at the prompt, mount -a to reload the table and be able to access the mount.
Cant ping own pc
Happened on a Dell PC where I couldn’t ping said machine despite ruling out all the daft stuff. I could ping Google and even the router – thus NIC is ok. I have a static IP
Obviously firewall was tested as part of the diagnosis.
For what it is worth, the hosts file was also checked to be correct.
1. view tcp/ip properties and capture all settings. Including gateway and DNS servers (which should be in your router, if you can remember the password to it).
2. tracert google.com, see whats happening.
3. delete ip from any tables: e.g. arp -d 192.168.n.n
4. clear any arp cache: netsh interface ip delete arpcache
5. netsh int ip reset reset.log
6. reset your settings in the TCP/IP propertues
6. reboot (well, it is Windohs and it is required)
7. enjoy being able to run your TCP/IP enabled apps and ping yourself like mad but don’t complain to me if it still doesn’t work! This is about as deep as I go.