Running a shell command when UPS power is active.
I am hoping someone can help me create a shell command that will execute an automator workflow to send an email when my server has switched to UPS power.
I've created an automator workflow that opens mail, creates an email, and sends it. Now I need to create a way to execute the workflow when the server switches from AC power to UPS power.
Is this whole setup even possible? I have never written apple shell commands before so that is where I need the most help.
Thanks!
Resending it again
Similar Messages
-
Run a shell command using Pl/Sql
hi all
i wonder if anyone knows a way to run a shell command using pl/sql
other than java stored procedure
as it seems not to be working in my case
thanx in advance,
Rashaofcourse not
i sent it once then i've got disconnected from interent then i reconnected
and resend my question so it was sent twice
now i hope you can answer my question !!!
Do you really think when asking twice or more often you will get a quicker answer? -
Running a shell command in windows
Hi All,
I am facing trouble trying to run the unix command in windows. I know that Runtime.getRuntime().exec(command) has to be used for this purpose. I have a slightly different requirement , i.e it is not simply executing the command.
Before I execute a command say " export $KEY_SETTINGS " I need to invoke the mks shell and then execute a shell (which sets few variables).
So the code which is written (not working though :( ) is
osCommand = "export $KEY_SETTINGS "
pathMKS = "C:\\temp1\\mksnt\\mksnt\\sh.exe";
pathENV = "C:\\\\temp1\\\\temp2\\\\Environ.sh";
command[0] = "cmd";
command[1] = "/c";
command[2] = pathMKS + " -c " + "\". " + pathENV + " ; " + osCommand + "\"";
report.println("Comanda="+ command[0] + ' ' + command[1] + ' ' + command[2]);
Process process = Runtime.getRuntime().exec(command);
bufferedreader = new BufferedReader(new InputStreamReader(process.getInputStream()));
bufferedreaderErr = new BufferedReader(new InputStreamReader(process.getErrorStream()));
for(int i = 0; (s = bufferedreader.readLine()) != null && i < 1; i++) {
commandOut = commandOut + s + "\n";
report.println("Print env:" + s);
while((s = bufferedreaderErr.readLine()) != null) {
commandErr = commandErr + s + "\n";
if (!commandErr.equals("")) {
throw new RuntimeException("Error running command: " + command[2] + "\n. Error: " + commandErr);
The error I am getting is
"Error running command: C:\oracle\mksnt\mksnt\sh.exe -c ". C:\\oracle\\appl\\Apps.sh ; export $KEY_SETTINGS "
Error: Export: not found.
Please help me out in this.
Best Regards
ShreyResending it again
-
Issues with running UNIX shell command from Java
Here is my java class file:
create or replace and compile java source named host as
import java.lang.* ;
public class Host
public static void cmdTest()
String cmd = "ps -ef | grep orcl" ;
int rc = 0 ;
int = runCmd(cmd) ;
public static int runCmd(String str )
Runtime rt = Runtime.getRuntime() ;
int rc = -1 ;
try
Process p = rt.exec(str) ;
int bufSize = 4096 ;
BufferedInputStream bis =
new BufferedInputStream(p.getInputStream(), bufSize) ;
int len ;
byte buffer[] = new byte[bufSize] ;
// Log what the program spit out
while ((len = bis.read(buffer, 0, bufSize)) != -1)
rc = p.waitFor() ;
catch (Exception e)
e.printStackTrace();
rc = -1 ;
finally
return rc ;
show errorsI can call runCmd directly from SQLPlus using an Oracle stored procedure and it runs like expected. I can see the returned output using dbms_java.set_output(1000000).
But when I call cmdTest from SQLPlus using an Oracle stored procecdure it just hangs forever and I have to kill the session.
Is there something I am missing in the cmdTest method?Jimmy,
If you haven't already seen it, I think the following article may be of help:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
Also a "finally" block should not contain a "return" statement:
http://weblogs.java.net/blog/staufferjames/archive/2007/06/_dont_return_in.html
Good Luck,
Avi. -
Can I execute commands when my system switches to UPS battery or shutdown?
Hi, I am trying to execute some custom commands when the power goes out and my mac is running on battery from an uninteruptible power supply (UPS). I did some research and read that a script is executed when OS X shuts down when critera are met while its is running on battery from a UPS. UPS is supported by Mac OS because it shows up in the Energy Saver Preference plane.
This script is: /usr/libexec/upsshutdown
I modified this script, but it looks like my custom commands are not executed.
Does anyone know if mountain lion still executes this script?
2012 Mac Mini Server
CyberPower CP1000PFCLCDOkay. I think I know what the problem is. Here's the exact sequence I follow. I am thinking SQL Developer is not doing exactly what it should.
a) File > New and then click okay
b) The top dialog box shows the file name: Untitled2.sql
c) I rename this to abcd and click okay
d) SQL worksheet opens with the following filename "abcdsql" <- there's no dot between abcd and sql !
e) I enter in "select * from dual"
f) execute and it works fine
g) I click save and it saves it as abcdsql <- NO extension
Before I had not been looking carefully. I had seen the word "abcdsql" and thought it was "abcd.sql".
Now my question is why does it append "sql" to the filename? I was in the box for naming a new sql file. It allowed me to type in a file name but then instead of adding "sql" as an extension it just appended this to the filename and didn't give it an extension.
Anyone else tried this? It seems like a very non-standard thing to do. I never saw an application that just appended "sql" to the filename when it should have given the file a ".sql" extension.
Richard -
hi all
i wonder if anyone knows a way to run a shell command using pl/sql other than java stored procedure
as it seems not to be working in mycase
thanx in advanceSatish,
Would you be kind enough to share some sample code for us? I am interested to see that.
My take on it was exactly as Richard's, I would do it the other way round, wrap PL/SQL in UNIX and I could accomplish everything that you are mentioning like doing ftp, running SQL* Loader etc..
There may be specific situations where they may need the opposite, that is why I am interested to see the code.
Thx,
Sri -
Can I change user name after running essbase from command prompt??
Hi,
I run essbase from command prompt and during this activity I was asked to give user name and password, but by mistake I put wrong user name and now wolud like to chanege it.
Is it possible??
cheers,It worked,
now I was able to connect to easbase from planning, I ve created sample aplication and initialize it but cannot connect to Eas to download data for sample application. After I run the validation there is now only one error displayed:
Essbase / Essbase Administration Services
FAILED Web App Availability of web application context (POL-MPIKULSKI 10080, eas)
Error: com.hyperion.cis.utils.BadResponseCodeException: Bad response code: 404
Recommended Action: Check application is started
I tried to start the eas from start>programs>epm system>essbase>administration services>start administration services(java embeded) but it didnt help.
can I start in in different way??
cheers, -
Shell Commands not found error when running application
Hello,
Im using MonoDevelop IDE in my Mac, before it used to work fine but after few days, now when I'm opening the application nothing happens., i checked the Console for the log and it says this
May 9 21:29:39 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x52052].com.ximian.monodevelop[1510]: /Applications/MonoDevelop.app/Contents/MacOS/monodevelop: line 17: dirname: command not found
May 9 21:29:39 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x52052].com.ximian.monodevelop[1510]: /Applications/MonoDevelop.app/Contents/MacOS/monodevelop: line 31: //mono-version-check: No such file or directory
May 9 21:29:39 Sri-Vishnu-Totakuras-MacBook-Pro com.apple.launchd.peruser.501[599] ([0x0-0x52052].com.ximian.monodevelop[1510]): Exited with code: 1
I thought may be some error with the "dirname" command, so i commented it in the code and gave the path of directory myself and then the console shows up like this.
May 9 21:34:12 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x56056].com.ximian.monodevelop[1532]: /Applications/MonoDevelop.app/Contents/MacOS//mono-version-check: line 19: grep: command not found
May 9 21:34:12 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x56056].com.ximian.monodevelop[1532]: /Applications/MonoDevelop.app/Contents/MacOS//mono-version-check: line 19: cut: command not found
May 9 21:34:12 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x56056].com.ximian.monodevelop[1532]: /Applications/MonoDevelop.app/Contents/MacOS//mono-version-check: line 20: cut: command not found
May 9 21:34:12 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x56056].com.ximian.monodevelop[1532]: /Applications/MonoDevelop.app/Contents/MacOS//mono-version-check: line 21: cut: command not found
May 9 21:34:12 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x56056].com.ximian.monodevelop[1532]: /Applications/MonoDevelop.app/Contents/MacOS//mono-version-check: line 22: cut: command not found
May 9 21:34:12 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x56056].com.ximian.monodevelop[1532]: /Applications/MonoDevelop.app/Contents/MacOS//mono-version-check: line 31: osascript: command not found
May 9 21:34:12 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x56056].com.ximian.monodevelop[1532]: Cannot launch MonoDevelop
May 9 21:34:12 Sri-Vishnu-Totakuras-MacBook-Pro [0x0-0x56056].com.ximian.monodevelop[1532]: MonoDevelop requires the Mono Framework version 2.10.4 or later.
May 9 21:34:12 Sri-Vishnu-Totakuras-MacBook-Pro com.apple.launchd.peruser.501[599] ([0x0-0x56056].com.ximian.monodevelop[1532]): Exited with code: 1
I opened the contents of the application and run the shell script for opening aplication there it worked very fine and application started working.. But if i open application directly through launchpad or finder it doesnt show up and console
I tried running those commands in the terminal directly there they work.. But dunno whats wrong in here. and even if try to open the application through the terminal it all opens fine.. what could be the possible problem, is it with my mac..?i finally figured out the problem.. it is with the environmental variables. the path for all those commands like "grep" is not being set for the GUI applications. that is why i got that error.
for those GUI applications which require path, we have to set path in the file /etc/launchd.conf the environmental variables set in here are used by the gui applications and those which are launched through spotlight.
that file may bot be present in most of the macs. No problem even if not present,we can create one and use.
so type in terminal
$ sudo vi /etc/launchd.conf
and in the editor add these lines
setenv PATH = /new/path
and save. Note: replace /new/path with the path which you need to have for the commands used in the script.
remeber that you need to restart your mac for applications to use these environmental variables. -
How to run 'Get-AssignedAccess' or 'Set-AssignedAccess' power shell commands in c# Application
Hi,
I have console application using which i am trying to run power shell command like 'Get-AssignedAccess' or 'Set-AssignedAccess'.
i am using below code for this it is throwing exception 'Get-AssignedAccess' doesn't exist in cmdlet which is correct because these commands belongs to function category.
using (PowerShell pwInstance = PowerShell.Create())
pwInstance .AddScript("Get-AssignedAccess");
var result = pwInstance .Invoke();
How can we execute this kind of command using c#?
Thanks,Hi prakashlight,
Thank you for comming back and tell us the result. For more information about how to run PowerShell script in C# language, you can refer to this blogpost here:
Executing PowerShell scripts from C#
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Need a power shell command for Front End fail over?
We have a Lync 2013 infrastructure with 2 front ends and 2 edges.
The environment was setup by a partner and the servers were configured for failover in case one goes down in the pool.
However the last time windows updates were applied and the primary FE had to be restarted, the secondary FE did not automatically switch over as the active server and it caused a companywide outage.
In speaking with the contractor, they said that well no it would not automatically do this, you need to run a Lync PowerShell to have it switch over.
My BS radar went off, but I wanted to ask you if this sounds right or is possible.
If it must be done, could you give me the power shell command.
ThanksHi,
Did you solve the issue with the help of the people above provided?
If you use a Lync server Enterprise edition, it is recommended to deploy at least three FE servers.
If you use two Lync server Standard edition for DR,
when one of the servers fails in the Pool Pair, the administrator need to manually failover the pool to the other member of the Pool Pair using the
command: Invoke-CsPoolFailover -PoolFQDN <Pool1 FQDN> -DisasterMode -Verbose
The Automatic failover and failback for
Voice option and the associated time intervals in Topology Builder apply only to the voice resiliency features that were introduced in Lync Server 2010. Selecting this option does not imply that the pool failover discussed in this document is automatic.
Pool failover and failback always require an administrator to manually invoke the failover and failback.
You can refer to the link below about how to failover a pool:
http://technet.microsoft.com/en-gb/library/jj204678.aspx
Best Regards,
Eason Huang
Eason Huang
TechNet Community Support
Does it help, yes and no. FYI, we are running Enterprise Edition front ends for our single pool. The new environment was setup as a proof of concept and we installed the bare minimum # of servers at the time.
The articles suggested from above pretty much just say if one of your FE's goes down, bring it back up as soon as possible. Both of our FE's need windows updates applied ASAP and it could an hour or more (likely). Here is a quote from the article:
If for some reason you need to bring both servers down at the same time, do the following when the downtime for the pool is finished:
The best practice is to restart both Front End Servers at the same time.
If the two servers cannot be restarted at the same time, you should bring them back up in the reverse order of the order they went down.
If you cannot bring them back up in that order, then use the following cmdlet before bringing the pool back up:
Reset-CsPoolRegistrarState -ResetType QuorumLossRecovery -PoolFQDN <FQDN>
The last time the main FE went down for service, we left the secondary FE on but there was still an outage. Then brought back the formerly active FE fist and service was restored. Basically I need to know how to switch the passive to the active
node before/while the primary is offline. And if required once both FE's are back up, to switch the service from the secondary that became active, back to the primary server as it was before. Make sense? Perhaps I'm still missing something
after reading the articles. The powershell commands list just updating the topology after both servers come back online. -
My Macbook Pro 17" 2.44ghz all of a sudden one day decided to not boot up. When the power button is pressed the sleep light in the front on the latch release turns on and there is a small running sound but it never boots up and the screen never lights up. Anyone else have this problem? Any ideas?
I'd love to repair it but not if it'll cost 500 bucks or more to replace the logicboard.
I appreciate any help
MichaelLao Bo,
yes, you can locate and copy a file from your HD to a USB key using UNIX commands. If you know the exact name of the file which you’re trying to locate, try this:
find / -iname filename -print
This command will search your entire internal disk for the particular filename. If you know that it’s within a particular user account, then you can save search time with this variation:
find /Users/username -iname filename -print
Either variation of this command will print all files found which have the given filename. Presuming that you’re able to identify the correct file, you can copy it to a USB key using the command
cp -p filename_returned_by_find /Volumes/USB_volume
If you’re not sure which volume name your USB key has, this command will show you what the possibilities are:
ls /Volumes
Please let me know if you have any trouble with these commands. -
Power shell command not working in Power shell ISE
I was looking for guidance on a problem I was having and found a post from
Bigteddy on TechNet that had this command
Get-ADUser -Identity sam -Properties memberof | select -ExpandProperty memberof
I kept trying it many ways and it always fails in power shell ISE.
I get the below output
The term 'Get-ADUser' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of
the name, or if a path was included, verify that the path is c
orrect and try again.
At line:1 char:11
+ Get-ADUser <<<<
-Identity rwhite -Properties memberof | select -ExpandProperty memberof
+ CategoryInfo
: ObjectNotFound: (Get-ADUser:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I put the same command in the power shell module window and it works perfectly
Any idea how I can make this work for striping purposes in power shell ise
ronald whiteImport-Module ActiveDirectory
If that returns an error, chances are that you do not have the module on your computer. You can verify that by running
Get-Module -ListAvailable
Rich Prescott | Infrastructure Architect, Windows Engineer and PowerShell blogger | MCITP, MCTS, MCP
Engineering Efficiency
@Rich_Prescott
Windows System Administration tool 2.0
AD User Creation tool -
How to Execute Power Shell Command From Windows Application.
Hi All Experts,
I want to execute power shell commands from my windows application.
Is it possible ?
Please let me know your comments..
Thanks.I have not tried this, but apprently it is easy as in the sample pasted below. please see this article for more details
http://geekswithblogs.net/Norgean/archive/2012/09/19/running-powershell-from-within-sharepoint.aspx.
Let me know how it goes...
public string RunPowershell(string powershellText, SPWeb web, string param1, string param2) {
// Powershell ~= RunspaceFactory - i.e. Create a powershell context
var runspace = RunspaceFactory.CreateRunspace();
var resultString = new StringBuilder();
try
// load the SharePoint snapin - Note: you cannot do this in the script itself (i.e. add-pssnapin etc does not work)
PSSnapInException snapInError;
runspace.RunspaceConfiguration.AddPSSnapIn("Microsoft.SharePoint.PowerShell", out snapInError);
runspace.Open();
// set a web variable.
runspace.SessionStateProxy.SetVariable("webContext", web);
// and some user defined parameters
runspace.SessionStateProxy.SetVariable("param1", param1);
runspace.SessionStateProxy.SetVariable("param2", param2);
var pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(powershellText);
// add a "return" variable
pipeline.Commands.Add("Out-String");
// execute!
var results = pipeline.Invoke();
// convert the script result into a single string
foreach (PSObject obj in results)
resultString.AppendLine(obj.ToString());
finally
// close the runspace
runspace.Close();
// consider logging the result. Or something.
return resultString.ToString();
Ok. We've written some code. Let us test it.
var runner = new PowershellRunner();
runner.RunPowershellScript(@"
$web = Get-SPWeb 'http://server/web' # or $webContext
$web.Title = $param1
$web.Update()
$web.Dispose()
", null, "New title", "not used");
-Sangeetha -
[solved] hook to run commands when user logs in? (before bash profile)
Is there any way to run commands when a user logs in but before the bash profile is sourced?
For example, I have a user account with a home directory on /tmp. When the user logs in, the home directory might not exist so there will be no .bash_profile to source. I want to run a script to create the directory if necessary and copy some files into it. How can that be done?
I thought of putting something in /etc/profile or /etc/profile.d/, but I would like to run something before the user's shell and environment become active.
I can use /etc/rc.local to do what I want, but I would prefer a hook to ensure that everything is set right when the user logs in.
Any ideas?
*edit*
Solution
In my case, I found that I could write my own shell script and set it as a login shell. In the script, I can configure everything I need before launching the interactive shell, then clean up anything after it exits.
Last edited by Xyne (2011-12-10 19:34:07)Thanks, dammannj. PAM could probably do what I need but I think I have found a simpler solution (see original post).
-
Run shell commands using java program
Hi guys,
I am trying to run shell commands like cd /something and ./command with arguments as follows, but getting an exception that ./command not found.Instead of changing directory using "cd" command I am passing directory as an argument in rt,exec().
String []cmd={"./command","arg1", "arg2", "arg3"};
File file= new File("/path");
try{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd,null,file);
proc.waitFor();
System.out.println(proc.exitValue())
BufferedReader buf = new BufferedReader(new InputStreamReader(proc.getInputStream()));
catch(Exception e)
{e.printStackTrace();
So can anyone please tell me what is wrong with this approach? or is there any better way to do this?
Thanks,
Hardikwarnerja wrote:
What gives you the idea that the process to execute is called "./command"? If this is in Windows, it is "cmd.exe" for example.It does not have to be cmd.exe in Windows. Any executable or .bat file can be executed as long as one either specifies the full path or the executable is in a directory that is in the PATH.
On *nix the file has to have the executable bit set and one either specifies the full path or the executable must be in a directory that is in the PATH . If the executable is a script then if there is a hash-bang (#!) at the start of the first line then the rest of the line is taken as the interpreter to use. For example #!/bin/bash or #!/usr/bin/perl .
One both window and *nix one can exec() an interpreter directly and then pass the commands into the process stdin. The advantage of doing this is that one can change the environment in one line and it remains in effect for subsequent line. A simple example of this for bash on Linux is
import java.io.OutputStreamWriter;
import java.io.Writer;
public class ExecInputThroughStdin
public static void main(String args[]) throws Exception
final Process process = Runtime.getRuntime().exec("bash");
new Thread(new PipeInputStreamToOutputStreamRunnable(process.getErrorStream(), System.err)).start();
new Thread(new PipeInputStreamToOutputStreamRunnable(process.getInputStream(), System.out)).start();
final Writer stdin = new OutputStreamWriter(process.getOutputStream());
stdin.write("xemacs&\n");
stdin.write("cd ~/work\n");
stdin.write("dir\n");
stdin.write("ls\n");
stdin.write("gobbldygook\n"); // Forces output to stderr
stdin.write("echo $PATH\n");
stdin.write("pwd\n");
stdin.write("df -k\n");
stdin.write("ifconfig\n");
stdin.write("echo $CWD\n");
stdin.write("dir\n");
stdin.write("cd ~/work/jlib\n");
stdin.write("dir\n");
stdin.write("cat /etc/bash.bashrc\n");
stdin.close();
final int exitVal = process.waitFor();
System.out.println("Exit value: " + exitVal);
}One can use the same approach with Windows using cmd.exe but then one must be aware of the syntactic differences between commands running in .bat file and command run from the command line. Reading 'help cmd' s essential here.
The class PipeInputStreamToOutputStreamRunnable in the above example just copies an InputStream to an OutputStream and I use
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class PipeInputStreamToOutputStreamRunnable implements Runnable
public PipeInputStreamToOutputStreamRunnable(InputStream is, OutputStream os)
is_ = is;
os_ = os;
public void run()
try
final byte[] buffer = new byte[1024];
for (int count = 0; (count = is_.read(buffer)) >= 0;)
os_.write(buffer, 0, count);
} catch (IOException e)
e.printStackTrace();
private final InputStream is_;
private final OutputStream os_;
}
Maybe you are looking for
-
Reading File from a Desktop/ShareFolder in SAP MII 14.0
Dear Experts, I have a situation where I want to read a CSV file from a source different than SAP MII server. Basic intention is to read a file from a desktop or some shared folder. My first doubt is- Is it really possible in SAP MII 14.0 version? Bu
-
Bizarre behavior of a View Criteria for a View Object
Hey, I remarked quite a bizarre behavior of the View criteria that I created for my view object, using bind variables. lets say I have the generated query in the View object: SELECT Paquet.ID, Paquet.WEIGHT, Paquet.VALUE, Paquet.ORIGIN, Paquet.DESTIN
-
How can i center a pop up window?
hello, i am trying to get the new window that will open after clicking a link with an onClick beheavior to span the entire length of a monitor displaying a 1440 pixel resolution . when the user clicks the link & the new window opens, it pops up relat
-
Secatt Recording Multiple line items
Hi all, Iam new to secatt. Iam having couple of doubts: 1) We having the scenerios :Creating script for Purchase,Order. P.O had multiple line item's.I want to creat the script for P.O ,that should work for all line items,each line items had deliery
-
Reproducable Kernel Panic when streaming via Mplayer X or VLC (27" iMac, ATI5750)
Since Lion (and yes, I did install 10.7.1) I have an odd behavior: When streaming von my Dreambox to VLC or Mplayer X I get a Kernel Panic after 5-15 Minutes. Everytime. Always. I have a iMac 27" 2.8 i5, 8GB Memory, and an ATI 5750 (1024MB). And righ