Can anyone explain how to shutdown the Linux system using system command? - linux

I stuck in a problem, I want to shutdown the Linux PC using system command but my machine is asking to enter the password.
here is the scenario: I'm using 2 systems one is windows and another one is Linux. I'll send the command to Linux for shutdown, this Linux PC application made it as Service file, once I receive the command for shutdown, My Linux PC run the system function which is written like this system("shutdown -P now"); if I run this command my machine won't execute the command.
Kindly help me out in this!
Thanks & Regards

thank you Some programmer dude for your valuable feedback. Posting your suggestion as answer to help other community members.
The shutdown command needs super-user privileges. You can use some
additional commands to elevate the privileges along with the command
you are currently using.

Related

Google Chrome hanging in CentOS 7

I am using Linux platform (CentOS 7). sometimes i get my system just hang and then i need to do restart my system directly from power so anyone know how to rectify this issue without restart my system.I am fed up with every time restart my system. so please help me out.
I know here i will get my answer that's why i posted my question here.
Thanks in advance!!!
You can goto text mode and kill the process which process are running in your system,
Press CTRL+ALT+F2 and goto textmode.
Type your username and password
Write command ps -eaf|grep chrome (you can see here which process is
running and take that process number just like task manager in
windows)
Now need to kill that process so Write command kill -9 [process#]
once process will kill you can comeback again in graphics mode with
CTRL+ALT+F1
I hope this this answer will helpful for you beacuse this process is work fine for me when my any application stuck. :)

Connect to a remote desktop

I would like to remotely control a windows server from Linux Ubuntu. I am able to connect using the rdesktop command I was however wondering if there is a possibility to, for example, restart a service, or manually pull the server out of a pool, restart it and put it back simply using the command line.
If you know about any useful commands that would be great :) I am however simply trying to figure out if this is actually even possible as I am new to Linux...
Thanks in advance!
You are basically asking about how to control Windows from the command line. If you are able to connect to the screen of a Windows PC and open a socalled "dosbox" you can issue any command you like (and your permissions grant to you)
Services can be controlled with the sc command, a restart can be used with the shutdown command. Besides that you can call many more functions, from the classic command line or even with Powershell.
But all of this is based on manual interaction.

Where are the device file kept for each keyboard console shell on a Linux machine?

I am trying to find where the keyboard is kept on a linux system?
Is it under /dev/input?
Thank you!
You are probably working with terminal in Linux, so that's why you are looking for terminal device driver. I think these two links are a good answer for you... explaining the difference between TTY, PTY & PTS.
https://unix.stackexchange.com/questions/21280/difference-between-pts-and-tty
http://tldp.org/HOWTO/Text-Terminal-HOWTO-7.html
But to add, deciding which one is you choice depends on the way you are connected to Linux machine ... this link helps on this issue:
what is the difference between tty and vty in linux
Cheers

Using JNA or similar to shutdown and restart computer in linux and mac

I am trying to write a function in java that will shutdown, force shutdown, restart and force restart the computer and it should work on Windows, Linux and Mac.
Windows is not a problem, but I am unable to run commands to shutdown on Linux due to the sudo privileges. I was therefore thinking of using JNA to shut down the computer (i know you can use JNA to do this on windows), but I can't find any examples online for linux or mac.
Can anyone help me out? It will be much appreciated!
Even if it's not through JNA, it would help me a lot as long as I can find some way to accomplish this.
If you could simply override system protections just by using Java, that would be a big security flaw! I'm surprised you can do this on Windows.
Anyway, it can only be done if you have administrative access to your machine to set the program in a certain group which has the rights to shutdown/restart. Otherwise, you can't just do that.
I think you could give directly these rights to your JVM, but that could be dangerous if other java programs try to do shutdown.

Calling Linux command line in MATLAB

I have recently learned, that in MATLAB, the "!" mark runs the code in a command line and follwed by the "&" will pull up the command window, FOR EXAMPLE:
!RUN_FILE.bat&
It was a great day when I discovered this, or should I say when someone told me this. Anyways I was wondering if there was a way to run this batch file on a linux machine that I am connecting to remotley with a Windows desktop? (I am a newbie when it come to anything Linux, so if it doesn't make sense let me know and please dumb down you answers if you don't mind) haha
THANKS,
ME
The Linux shell doesn't understand batch files. That's not to say that the batch file can't be re-written to work in the Linux shell. Post some more information about the Linux shell you are using and your batch script and perhaps we can help you port it to Linux.
On a second read of your question, I interpreted it a different way. Are you running Matlab on a Linux machine that you are remotely connected to, or are you running Matlab on your local Windows machine and you want to send the ! command to the remote Linux box?
If the latter is true, then you should probably be able to write a batch file (to run from Matlab) that will launch the remote script on the Linux box. How are you connected to the Linux machine? VNC? SSH?
Windows and Linux use different shell scripting languages, so you couldn't run a .bat directly on Linux, but could create a bash script to perform the same actions.
You might want to see this bat2bash online converter (I prefer re-writing though):
http://www.filegod.netfirms.com/Bat2Bash.html

Resources