remotely determine using ssh IF a machine needs to be rebooted [closed] - linux

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
There are plenty of examples of HOW to reboot a linux machine via SSH. However, in my case I want to check IF a linux machine needs to be rebooted via SSH. I have an agent that checks a machine for various metrics and reports that back to a central alarm console. I want to add the ability to check if a machine requires a reboot since some of them have security updates automatically installing.
I don't want to have to enable something on each machine as I prefer to run one script from one location preferably with a single command to check remotely.
EDIT: To clarify, I was looking for a file on a machine that would indicate whether a machine requires a reboot. I then wanted to check for the existence of that file (or something else) remotely using SSH where I am already doing other checks on a group of machines on a nightly basis. I didn't necessarily want to trigger a reboot if it was determined a reboot is required.
The answer I was looking for is below that's referencing /var/run/reboot-required which lead me to to this link.

You can check if the file /var/run/reboot-required exists.
In a bash script, you can use:
#!/bin/bash
if [ -f /var/run/reboot-required ]; then
echo 'A reboot is required'
restart -r now
fi
That way, the script will reboot your machine if a required reboot is pending.

There are plenty of examples of HOW to reboot a linux machine via SSH.
Since you're logged into that machine through SSH then the way to reboot is the same. restart -r now would restart that machine immediately.
I want to check IF a linux machine needs to be rebooted via SSH.
In that case you could check if your conditions are met in a bash script like,
if [ yourCondition ]; then
restart -r now
fi

Related

WSL - GEDIT Unable to init server: Could not connect: Connection refused [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I'm using Ubuntu 18.04 as Windows Subsystem for Linux on my Windows 10 machine.
I've installed gedit without any errors or warnings.
But whenever I try to use the command gedit something (here something is a filename)
I get this error:
Unable to init server: Could not connect: Connection refused
(gedit:48): Gtk-WARNING **: 21:03:26.729: cannot open display:
You need an X server to run graphical applications like gedit.
I use VcXsrv or Xming on my Windows desktops, both are very small and easy to install,
but there exist other servers like Cygwin/X.
Short instructions for VcXsrv/Xming:
download and install the Windows package
start XLaunch or Xming
export the DISPLAY variable in your WSL terminal and start gedit
export DISPLAY=0:0
gedit
I have the problem that some checkboxes in gedit's preferences are not working (dconf error, I don't care), but other than that the editor is usable.
Related:
What's the easiest way to run GUI apps on Windows Subsystem for Linux as of 2018? (askubuntu.com)
To fix this problem
Step 1- Download and Install this Windows X Server https://sourceforge.net/projects/vcxsrv/
Step 2- Open XLaunch
Step 3- Select " Full screen " option
Step 4- Choose " Start no client " option
Step 5- Simply do next and finish
Step 6- Open terminal and type :
export DISPLAY=0:0
gedit filename
In case your Linux machine is available with host name = 'hostname' and you'd want to ssh into the hostname and then open gedit then execute the following commands:
Enable X11Forwarding in the ssh server
[hostname] $ vim /etc/ssh/sshd_config
# and set X11Forwarding to yes
X11Forwarding yes
Set the DISPLAY env in the client terminal and then ssl with -X flag
export DISPLAY=0:0
ssh -X yourusername#hostname
[hostname] $ gedit filename
It's probably because you are running it with root user.
Run it as non-root user.
(If you don't know that if you are running it as root or not, enter the command below and if it returns 0, it means you are root and you must to login to non-root user: id -u)
(If you had run sudo su or something like that, It means you are root and you must use exit to go back!)

Executing bash script on remote and "command not found" [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
I'm trying to execute a bash script using ssh.
Say there is machine A and B. The bash script is on A and it has a command using a package installed locally in A. The package is not installed in B. I am trying to run the script from A when sshing to B. But I am constantly getting 'command not found'.
This is what I did:
ssh username#server 'bash -s' < local/path/to/file
I am wondering that is it because I don't have the package installed on B, the server? Is there any way that I can execute the script using B without having to install the package on it (my account do not have the write access to the directory)?
Theoretically you could, with lots of effort, embed the entire software in question in your script and pass that on the SSH standard input. But in the case of a properly secured server (which could even be a different platform) and a compiled program with lots of dependencies this could be anything from tricky to a multi-year project.
The trivial case of the "package" being just a single-line shell script without dependencies you could simply copy the contents of the script into your script. But the vast majority of cases are going to be orders of magnitude more difficult.
The commands passed to ssh inside the single quotes are executed on the remote host; therefore, those commands must exist on the remote host in order for them to execute there.

Execute my Shell and Bash scripts without starting my terminal in Ubuntu [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I'm a user of Ubuntu 12.04 LTS and in a future a user of Ubuntu 14.04 LTS.
I have a problem, when I run Ubuntu my .bashrc script doesn't work unless I open the terminal.
This is a problem because, for example, the paths I write doesn't work unless I execute the programs from the terminal.
Are there an user config startup file for Ubuntu and not for the terminal?
P.D.:Maybe I don't explain very well, in other words, I'd like to execute mi scripts on Ubuntu startup without using the terminal.
Shell initialisation files (.profile, .bashrc, etc.) are intended for preparing the user's (interactive) environment.
For standalone scripts, it's better to make them independent from the environment, including
$HOME, $PATH, etc.
If you need to share code (functions, configuration) with other scripts, store that in a separate
shell library that you source from a known location, either through a fixed path or from a
path relative to the script's own location.
you can add the line below at the start of your script file
source ~/.bashrc
grep '/etc/bashrc' ~/.bashrc
if [ -f /etc/bashrc ]; then
. /etc/bashrc # --> Read /etc/bashrc, if present.
by default /etc/bashrc gets loaded when opening a console.
What are you trying to do - if you want to do something without it being executed as part of a console and more to do with system startup ? then you need to look into modifying existing service or adding a new service.
If this is related to when users ssh or connect it via console then its be bashrc file

Use PSFTP on Linux [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am using Linux Suse 10 and I am a complete noob when it comes to using it that's why I really needed some help.
The scenario is simple. I need to transfer some files from my linux server to a windows pc.
I already did this using FTP commands written inside a .scr file. Here's the content of my Upload.scr :
ftp -n 10.*.*.* <<SCRIPT
user administrator drowssap
cd TESTDIR
binary
lcd /path/of/the/txt/file/
put TESTUpload.txt
bye
SCRIPT
And then I would call it from linux Konsole using :
bash Upload.scr
It was actually working and could successfully transfer files to my windows pc. However, what I need is to transfer the files using "psftp".
The original code which works from windows-to-windows transfer is :
ProcessStartInfo PSI = new ProcessStartInfo("CMD.exe", "/C psftp " + UserName + "#" + IP + " -pw " + Password + " -b UpLoad.scr");
I needed to do the same to my linux-to-windows transfer (i.e. I needed to use psftp instead of just ftp or sftp).
Whenever I tried to type "psftp" on linux Konsole it would display the ff :
bash: psftp: command not found
I know there's something missing. What should I do first to make it work? Should I install some application or .exe file into my linux server?
I really need help.
Thank you very much in advance! :)
psftp is PuTTY's SFTP utility.
OpenSSH has one too, named simply sftp (without the p). It is very likely already installed on your Linux machine.
If you want to install PuTTY's psftp, you just need to run:
apt-get install putty-tools
or equivalent for your distribution.

Linux console: git command not found on x64 Cent OS [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I have a completely fresh install of 64 Bit Cent OS 5.7, this is in VirtualBox on top of 64-bit XP.
I'm trying to install SSU.
Problem: The command 'git' was not found. See "code" below please.
Have tried looking this up: /usr/local/git/ does not exist: git: command not found (on OS X 10.5)
I don't care about source code: I just want git to work so SSU will install so I can try to access the bank on what seems like a huge whim.
I am signed in to Gnome as root and seem to be able to access my computer normally without being harassed about passwords excessively and can create or edit files.
[root#localhost ~]# $ git clone https://github.com/wesabe/ssu
bash: $: command not found
Concerns
Unfortunately every single time I ask these kinds of questions and don't make clarifications I end up having to make those clarifications. So...
No negativity or rudeness intended what-so-ever: if the answer involves editing a text file or copy-and-paste actions please tell me the locations to do so in the file manager instead of console commands. I'm perfectly okay copying and pasting console commands for things that really should be done in the console though.
Note: there appear to be numerous "git" commands and numerous "ssu" commands. I do NOT know the difference between them and would really prefer someone who has solid expertise to answer so that I nor others end up accidentally trashing our copies of Linux as it's been very difficult to get anything to work and stay working thus extending my personal stay with XP.
I will be more than happy to both accept an answer and thumbs it up should it be helpful.
I would first try installing git. As root:
yum install git
According to here,
yum install git-core
If that doesn't work you could add the EPEL source. There are also RPMs for git.

Resources