I try to do a migration to Windows Server 2008 and i am new with script concept.
I have a .sh file to launch which contains :
cd RADIOROOT/PLAYERS
killall player_1
su - robotstream --command='/RADIOROOT/PLAYERS/player_1 -t /RADIOROOT/PLAYERS/player_1.conf' & > dev/null
First, how can i launch this .sh file on my IIS ? Do i have to change it in a powershell script ?
I tried to change it to a .ps1 file with some changes but not working. Anyone know how to do it ?
Then, do you have any website about changing this sort of script in order to make it work ?
Thanks for your help.
Assuming everything is the same on the Windows server as it was on your *nix server (same paths, robotstream takes the same arguments, etc) this should do the same thing in PowerShell:
cd C:\RADIOROOT\PLAYERS
Stop-Process player_1
$command = "robotstream --command='/RADIOROOT/PLAYERS/player_1 -t /RADIOROOT/PLAYERS/player_1.conf'"
Invoke-Expression $command
Save that with a .ps1 extension, and then run it from a PowerShell console.
As far as a website about converting SH scripts to PowerShell, you'll need to learn Bash (so you can understand the script you're converting), and PowerShell (so you know how to write the new script). There are plenty of good websites out there for both. Just Google "powershell tutorial".
Hope that helps. Feel free to ask for clarification.
Related
I am trying to use PowerShell to send a file from a Windows 10 dev box to a CentOS 7 server across a local area network.
When I run the following command from PowerShell in the Windows 10 dev box, Putty opens, but then closes before asking for password. And then the test file (index.html) is not present in the intended destination folder on the CentOS 7 server.
Start-Process 'C:\Program Files (x86)\PuTTY\pscp.exe' -ArgumentList ("-scp -pw password C:\projects\temp\junk\index.html some_user_name#192.168.1.5:/home/some_user_name/")
How can I diagnose what problem is causing this command to fail? And what specific steps need to be taken in order for the file to be successfully transferred from the devbox to the server?
I have double checked the obvious things, like the file paths, the user name, and the IP.
The above command is derived from this suggestion by #GrahamGold.
In general, there's nothing wrong with your command. It should work (if all arguments are correct).
To diagnose the problem, first test the command on Windows command-line (cmd.exe):
"C:\Program Files (x86)\PuTTY\pscp.exe" -scp -pw password C:\projects\temp\junk\index.html some_user_name#192.168.1.5:/home/some_user_name/
This way, the output is preserved and you will see, what went wrong (if anything).
The next step is to do the same in PowerShell script using call operator & (though the result should be the same):
& "C:\Program Files (x86)\PuTTY\pscp.exe" -scp -pw password C:\projects\temp\junk\index.html some_user_name#192.168.1.5:/home/some_user_name/
If that works, it's time to replace & with the Start-Process cmdlet, if you really want that. But in general, I do not see a point of that, unless you want to run the transfer asynchronously.
Though if you want to make you command portable, you need to add -hostkey switch.
See my answer to Using echo y as an automated response to a pcp hostkey prompt.
I am struggling with a problem. I have:
ServerA (is closer to me and much faster)
ServerB (is my website where I want the final file to stay)
so what I want to do with the shell script (either Windows batch or linux, I have cygwin installed) is, passing the filename as parameter:
1) upload with FTP a file to ServerA
2) login with ssh on serverB and wget the file from serverA
I managed to do 1 with a shell script, but I don't understand how to do step2 in the shell?
Thanks
I would recommend using scp to accomplish step 2. You can use the syntax:
scp path/to/file serverb#hostname:/path/to/destination.
You can read more about the syntax for scp here: http://www.hypexr.org/linux_scp_help.php
You could use TeraTerm which has a powerful scripting language to automate both tasks.
I believe that this is a silly question but is my first time in wich I do a script. I am working on Linux, in an embedded system, and I think that what I want to do is quite simple but for me is not working.
I need to set an ip, start the startx & server for graphical mode and give to my application permission and run it, so I try like this:
#!/bin/sh
#
#Start
#
echo "Start......"
ifconfig eth0 X.X.X.X
startx &
cd /home
chmod a+x myApplication
./myApplication
exit $?
And then I save my script like S80script and I put it in the /etc/init.d folder.
I ran it but after throw the startx server my application is not run.
How can I do this in a propertly way?
There is another way for do this?
Thank you so much and sorry because maybe it is a beginner question.
If your application need to acess the XServer than you need to export the DISPLAY environment variable.
Try to run the application using:
DISPLAY=:0 ./myApplication
I would suggest you to install (for learning purposes) Linux on your laptop, and become familiar with Linux and scripting on your laptop. Then, replace during debugging phase the first line #!/bin/sh with #!/bin/sh -vx or #!/bin/bash -vx if you can run that script in a terminal. You could also use logger(1) in your script. Read the Advanced Bash Scripting Guide even if it is imperfect.
startx is configurable (read the linked man page), and is starting some client applications (configured in e.g. /etc/X11/xinit/xinitrc or in $HOME/.xinitrc...); so you should start your $HOME/myApplication from that file.
BTW, you could invoke startx in some init script like /etc/rc.local or whatever is appropriate for your Linux distribution.
BTW, you almost certainly need a window manager (to be started after your backgrounded application, as the last command, probably in the same xinitrc....).
At last, your embedded Linux distribution probably has some other files and scripts to start the network. You should configure your network parameters appropriately (on Debian and related, you could do that in /etc/network/interfaces)
I have one .sh file which runs well on MAC system. I want to run the same .sh file on windows using CYGWIN. My question is, Do I need to make any modification in the commands while using it in Windows system with CYGWIN? Please help.
e.g. I have the following commands in .sh file-
export ML_SERIALIZE_DIR=/Users/Mxyz/ML
export ML_SERIALIZE_GRAPH=true
echo ML_SERIALIZE_DIR = $ML_SERIALIZE_DIR
echo ML_SERIALIZE_GRAPH = $ML_SERIALIZE_GRAPH
java -DCL_LOG_DIR="/Users/Mxyz/ML" -classpath .:lib/:Ml-mobxyz-import.jar org.xy.mobxyz.mobxyz.ML
echo "Batch program is complete"
No need to change anything but make sure that all required binaries by your .sh must be there in CYGWIN
I have a task which is to run a batch file in IIS.. I had use C# to develop a webpage which need to run a batch file and uses plink to execute the batch file in the command. I had tried in localhost and it works perfectly. But when i deploy to IIS, it fail.
The coding i use which is
Process.Start(#"C:\run.bat");
inside run.bat is
cd\
plink root#172.28.8.* -pw ServerPassword useradd USERNAME -p UserPassword -m -g groupname -e 2011-6-6 -s /bin/bash -c *FULL_NAME*
plink root#172.28.8.* -pw ServerPassword -m pass
Is there any other way to do this??
or is there anyway something like this
i create the batch file using C# code, the batch file will store in IIS, then execute the batch file in IIS only return a successful message to the client.
Which mean everything done in server IIS. Is there anyway to do it??
Thanks in advance.
i have found the solution.
Inside this folder C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG, there is a file call Machine.config. Open with a notpad. Ctrl+F and search for processModel, then you will find this tag <processModel autoConfig="true"/>. Change it to <processModel userName="SYSTEM" password="AutoGenerate" />
As shown here .Then save it, make sure you backup a copy first, in case of maybe there are some errors occur.
I hope this help as many of them is searching for this problem(run Process.Start() in C#).
Good Luck!!