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.
Related
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 10 months ago.
Improve this question
I have an question about the .exe log. I am using raspberry pi 4 module with Debian OS where I am running my c-program from the .service base auto-start .exe process. Which is running well So whenever raspberry Pi will restart my program will start automatic.That's fine but how do I see my print-f log from the terminal.
When I run exe with below line it will print the message but when this .exe running through the auto-services how can we check the log ?
Is there any linux command which will help to print run-time message. ?
root#raspberrypi: $./test.exe
it seems that you are using a systemd service unit, to run your binary.
if so, you can use:
journalctl -u <name>.service
(replace <name> with the actual name of your service)
sidenote:
do not use the .exe extension for your elf-binaries ("linux binaries").
.exe is an extension for PE32 files ("windows executables"), but Linux is perfectly capable of running a file with an arbitrary name (extensions have no meaning under linux).
so: executables typically have no extension at all, and you should get used to that: use test instead.
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
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
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 have performed the following steps to install OpenLdap on my Redhat Linux Server:
1. untar the tar file
2. ./configure <--this ran successfully without error
3. make depend
4. make
5. make test <-- couldn't find any error
6. make install
7. started slapd: /usr/local/sbin/slapd
But the service is not starting. I don't see any slapd process in the ps -lef | grep slapd output. Also I see this, when i run : ldapsearch -x -b '' -s base '(objectclass=*)' namingContexts
ldap_sasl_bind(SIMPLE): Can't contact LDAP server (-1)
What could be the error and also How can I completely uninstall OPENLDAP
There are two questions here:
What could be the error?
It's possible that you haven't appropriately configured slapd. There are probably errors in your syslog (/var/log/messages) that will help you diagnose problems. You can also run slapd in debugging mode (slapd -d none) to see errors displayed on your terminal.
How can I completely uninstall OpenLDAP?
That's a little tricky, since you (a) elected to install it from source rather than using an existing package and (b) you didn't install it into a dedicated directory. To completely uninstall it, you would have to pay close attention to what files are installed by running make install and then remove them.
However, there's no harm in leaving the files installed on your system as long as you're not using them. You can remove anything that was installed into /usr/local/bin or /usr/local/sbin if you want to prevent them from conflicting with versions of those commands installed via system packages.
If OpenLDAP is the only thing you've installed in /usr/local you can just remove any files below that directory.
Generally, if you can use the pre-packaged versions of software available in your Linux distribution your life will be easier. For example, if you were to install the RedHat openldap-servers package, you would have a default configuration that would allow slapd to start and run correctly.
To uninstall. look through either the log output from the configure command, or type "configure --help" to see a list of directories that things are installed in by default. Most likely it populated files into /usr/local/bin, /usr/local/lib, and so forth, so you'll need to into those directories and remove the files by hand.
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.