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 2 years ago.
Improve this question
Is there any way to edit the ssh command in such way that 'ssh hostname' runs a bash script first before its standard function
Edit: Note that the ssh command's name stays the same, without adding anything to it.
Use shell alias. In your case:
alias ssh="echo 'hi'; ssh "
From now on, when you type ssh in the terminal, the shell will expand the alias.
In a shell script, you would need shopt -s expand_aliases for it to work.
You can use ProxyCommand.
Add to your ~/.ssh/config:
Host hostname
ProxyCommand /path/to/bash-script
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
what does this command do?
!/bin/bash
My first script
clear
echo (I don't know what will come after echo , can you help me with that too?)
./hello.shell
#!/bin/bash is called the shebang (you missed the leading #).
It tells which program will execute your script.
clear is for clearing screen.
echo outputs following argument to the standard output (your terminal by default). But you must not surround your string with parenthesis as it's used for grouping command in a sub-shell. If you want to print (...), you'll have too use double quotes :
echo "(I don't know what will come after echo , can you help me with that too?)"
./hello.shell will execute your script after you gave it execute permissions with chmod +x hello.shell.
Note that commonly used extension for a shell script is .sh rather than .shell.
For more, try theses links :
http://mywiki.wooledge.org/BashGuide/
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/
#!/bin/bash tells to the SO that this file is a script and that bash is the shell that must execute it. So you can found: #!/opt/bin/perl for perl scripts, #!/bin/csh for c-shell, #!/bin/zsh ...
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 9 years ago.
Improve this question
I am working on a Linux server, I have access to a directory but I am not allowed to write anything to that directory. I can run commands from system prompt. Now I have to find values of specific field of some files in that dir and do some comparisons. I have a script on a test server can do that. But I can't install my script to the server, I am asking if there is anyway I type a specific command, then I can write and run a shell program without saving the program? Thank you!
If you have the script on another host, you can run it this way:
wget http://your.host.net/script -O- | sh -s
If the host is not accessible via HTTP, you can use any other protocol you want.
Also you can write a script direct in a shell:
sh -s <<EOF
echo Hello
echo I am script
echo Nice to meet you
EOF
You can use backtics to execute the result of another command.
`wget /path/to/your/script/stored/remotely -O-`
(you might use sftp to fetch the script instead)
Another option is to write a program that uses a tty to control an ssh session, then the script is stored on the ssh client but the commands run on the server. Perhaps the expect tool would help with that.
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 alot of alias commands in Linux but how to protect each commands with p/w?
Lets say i made:
$ vi .bash_profile
alias goto1='echo ip=192.168.1.1, pw=abc; ssh root#192.168.1.1;'
alias goto2='echo ip=192.168.1.2, pw=xyz; ssh root#192.168.1.2;'
$ source .bash_profile
$ goto1
ip=192.168.1.1, pw=abc
root#192.168.1.1's password: _
That's the perfect taste of Unix/Linux based systems. And i'm using such things a lot!But the problem is:
How to protect these custom alias commands with password prompt?
For example, when i type $ goto1
Any bright idea!?
You can add those alias commands to (super_user) /root/.bashrc file.
Than you can use "sudo" restriction for normal user who wants to run that command with password or without password.
http://www.linux.com/learn/tutorials/306766-linux-101-introduction-to-sudo
You could put the credentials into a restricted permissions file eg
creds.txt
ip=192.168.1.1
pw=abc
then make it 0600 permissions so only you and root can read it. you alias would then be:
alias gotox='cat creds.txt; ssh root#<ip>;'
If another user trys to use the alias then they don't have permissions to read creds.txt and if they read your bashrc the sensitive info is not there.
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
How do I change shell in a remote PC? I am logged into a cluster with a Bash and the output I see is
elan#l01:~ $ chsh
chsh: can only change local entries; use ypchsh instead.
elan#l01:~ $ ypchsh
-bash: ypchsh: command not found
Since I have no root privilege there, I can not install ypchsh in the cluster. Is there any other way to change shell without invoking ypchsh?
Note 1:
Browsing, it looks like another user who installed the same software (currently not available for questioning) has .cshrc in his directory, with the right settings. His .bashrc is minimal and has no redirections.
The /etc/passwd has no entry for either of us.
getent passwd
shows entry for both of us, but shows only /bin/bash for both.
Note 2:
The sofware has been developed with autotools, and using bash instead of tcsh is known to have created wrong builds. (I am not changing shell because I fancy it.)
Thank you,
Elan
In your .bashrc, put exec tcsh last.
Once you're in bash in the cluster, why don't you just type tcsh? And if that works, why not just add it as the last line of .bashrc?
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 am trying to make batch commands (sh) on linux for start, stop and restart my web server lighttpd, with partial success.
Ideally, I would like to doubleclick icon and nothing more to do a job.
Now, on doubleclick appear dialog "Do you want to run "START.sh", or display its contents?" and "START.sh" is an executable text file." with Run in terminal, Display, Cancel and Run buttons. Run in terminal do a job after typing password.
My script look as follows:
#! /bin/bash
sudo /bin/bash /etc/init.d/lighttpd start
echo
echo -n " [ENTER] to continue... "
read var_keypress
Is here any way for my script to run without prompted dialog and that I don't need to type password every time?
You can configure sudo to be usable with no password as described here:
http://www.linuxscrew.com/2008/06/22/configure-sudo-nopasswd/
Be sure to let sudo only run specific commands without password, not all.
You could avoid that with a system init script (ln -s /etc/init.d/lighttpd /etc/rc2.d/S99lighttpd on Debian) or with a crontab entry for #reboot