I want to cd as well, but the path is not being passed from local to remote. I cant manually cd , this is part of a pipeline, so the cd has to be part of a variable based shell-script.
Any variable for that matter, is there a way to pass variables?
--- Post updated at 10:59 AM ---
Quote:
Originally Posted by RudiC
I think the problem lies in the escaping of the $ sign when expanding variables in your here document. Just as a rule of thumb: escape it to use a "remote" variable, don't escape it for using local vars. Having local and remote variables with identical names doesn't help debugging nor understanding what's going on...
Sorry about the confusion, I tried every combination without any luck,
You have a server onto which you want to log on using a certain user. If you connect from host A you want the user, after logging in, to go to one certain directory, if you connect from host B you want to go to another directory and so on. Is that right?
If so: there are several options you have. First you could use the output of who -a to find out from where you have connected. A sample output will look similar to:
Using this information you can create a script like this to change to the respective directory:
Notice that you may also have a variable "SSH_CONNECTION" set which holds essentially the same information.
Another possibility would be to use different users to connect to the host so you can have different login scripts which put you into different directories. All these users might at the end switch their effective UID (via su) so that you end up with always the same user but in different directories.
There will be a myriad of other possibilites, but as long as you do not explain what you (in the grand scheme of things) want to achieve it is hard to find out which one of them is feasible and which one isn't. So tell us about your plans and we will be better able to help you.
Location: Asia Pacific, Cyberspace, in the Dark Dystopia
Posts: 19,118
Thanks Given: 2,351
Thanked 3,359 Times in 1,878 Posts
Quote:
Originally Posted by senhia83
I want to cd as well, but the path is not being passed from local to remote. I cant manually cd , this is part of a pipeline, so the cd has to be part of a variable based shell-script.
Any variable for that matter, is there a way to pass variables?
--- Post updated at 10:59 AM ---
When I set up pipeline processes using ssh, I always use ssh without passwords by just exchanging public and private key pairs... (a one time setup, but saves a lot of time and effort afterwards)
In fact, even when I login for normal work, I mostly use password-less ssh with crypto keys. It is faster, more secure, and easier to set up pipelines of ssh commands.
Not quite. The echoed value shown in red above is also from the local shell; not the shell running on serverB.xxx.org. And, in Bourne based shells, the current working directory is stored in the variable named PWD, not the variable named pwd (and they are distinct variables because the shell is case-sensitive).
You probably want to replace that line in your script with either:
or:
and, if you're having any doubts about which variables are being expanded where, I would suggest using the 2nd form.
These 2 Users Gave Thanks to Don Cragun For This Post:
Hello All,
Hope you're doing well !
I am trying below command to be passed in a shell script, header_date_14 is a variable and $1 is the name of a file I intend to pass as a command line argument, however command line argument is not being accepted.
header_date_14=$(m_dump... (8 Replies)
I'm writing python script to get the file-names in the current directory and file sizes .I'm able to get file list and their sizes but unable to pass them through command line. I want to use this script to execute on other directory and pass directory path with file name through command line. Any... (1 Reply)
Hello friends,
I need to set PATH variable for all HP-UX users. I tried to implement it using /etc/profile and /etc/sshrc both none of them work.
I don't see sshrc file anywhere.
Please advise!
TIA (4 Replies)
Hi all,
Hereby wish to have your advise for below:
Main concept is
I intend to get current directory of my script file.
This script file will be copied to /etc/init.d.
A string in this copy will be replaced with current directory value.
Below is original script file:
... (6 Replies)
Hello again :)
Am currently trying to write a function which will delete a record from a file.
The code currently looks as such:
function deleteRecord() {
clear
read -p "Please enter the ID of the record you wish to remove: " strID
... (2 Replies)
Hi I'm trying to select text between two lines, I'm using sed to to this, but I need to pass variables to it. For example
start="BEGIN /home/mavkoup/data"
end="END"
sed -n -e '/${start}/,/${end}/g' doesn't work. I've tried double quotes as well. I think there's a problem with the / in the... (4 Replies)
Hello Folks,
I want to append a path in user's PATH variable which should be available in current session.
Background
Numerous persons will run a utility.
Aim is to add the absolute path of the utility the first time it runs so that next runs have the PATH in env & users can directly run... (6 Replies)
Hi,
Could anyone help me in writing a single line code by either using (sed, awk, perl or whatever) to extract a specific path from the PATH environment variable?
for eg: suppose the PATH is being set as follows
PATH=/usr/bin/:/usr/local/bin:/bin:/usr/sbin:/usr/bin/java:/usr/bin/perl3.4
... (2 Replies)
Hi
I need a script which will remove a path from PATH environment variable. For example
$echo PATH
/usr/local/bin:/usr/bin:test/rmve:/usr/games
$echo rmv
test/rmve
Here I need a shell script which will remove rmv path (test/rmve) from PATH... (9 Replies)
Hello everybody !
I have a first program, called "server" which build 2 FIFO's in this way:
...
#define PERMS 0666
#define FIFO1 "\tmp\cerere"
#define FIFO2 "\tmp\raspuns"
...
mkfifo(FIFO1, PERMS)
mkfifo(FIFO2, PERMS)
...
I want to access these FIFO's in a second separate program,... (1 Reply)