Sponsored Content
Full Discussion: Pass path variable on SSH
Top Forums Shell Programming and Scripting Pass path variable on SSH Post 303032662 by bakunin on Thursday 21st of March 2019 11:16:06 AM
Old 03-21-2019
If i get that right:

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:

Code:
bakunin@host $ who -a
           system boot  2019-03-20 15:29
           run-level 3  2019-03-20 15:29
LOGIN      tty1         2019-03-20 15:29              7581 id=tty1
bakunin + pts/0        2019-03-21 16:01   .          8762 (10.1.1.1)

Using this information you can create a script like this to change to the respective directory:

Code:
icomefrom=$(who -a | sed -n '/bakunin/ {;s/.*(//;s/)$//p;}')

case "$icomefrom" in
     10.1.1.1)
          cd /dir/A
          ;;

     10.1.1.2)
          cd /dir/B
          ;;

     .....
esac

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.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
 

10 More Discussions You Might Find Interesting

1. Programming

How to pass FIFO path to client process ?

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)
Discussion started by: Ametis1970
1 Replies

2. Shell Programming and Scripting

remove a path from PATH environment variable

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)
Discussion started by: madhu84
9 Replies

3. Shell Programming and Scripting

one liner to extract path from PATH variable

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)
Discussion started by: royalibrahim
2 Replies

4. Shell Programming and Scripting

Appending a path in user's PATH variable

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)
Discussion started by: vibhor_agarwali
6 Replies

5. Shell Programming and Scripting

Path a variable to sed that includes a path

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)
Discussion started by: mavkoup
4 Replies

6. Shell Programming and Scripting

How to pass a function with a variable parameter into another variable?

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)
Discussion started by: U_C_Dispatj
2 Replies

7. Red Hat

How to pass value of pwd as variable in SED to replace variable in a script file

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)
Discussion started by: cielle
6 Replies

8. HP-UX

How to set PATH variable for all HP-UX users when they login using ssh?

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)
Discussion started by: prvnrk
4 Replies

9. Shell Programming and Scripting

Pass File name and Directory Path through command to python script

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)
Discussion started by: etldeveloper
1 Replies

10. UNIX for Beginners Questions & Answers

Need to pass variable in a command and assign value to a variable

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)
Discussion started by: ektubbe
8 Replies
CREATEUSER(1)						  PostgreSQL Client Applications					     CREATEUSER(1)

NAME
createuser - define a new PostgreSQL user account SYNOPSIS
createuser [ option... ] [ username ] DESCRIPTION
createuser creates a new PostgreSQL user (or more precisely, a role). Only superusers and users with CREATEROLE privilege can create new users, so createuser must be invoked by someone who can connect as a superuser or a user with CREATEROLE privilege. If you wish to create a new superuser, you must connect as a superuser, not merely with CREATEROLE privilege. Being a superuser implies the ability to bypass all access permission checks within the database, so superuserdom should not be granted lightly. createuser is a wrapper around the SQL command CREATE ROLE [create_role(7)]. There is no effective difference between creating users via this utility and via other methods for accessing the server. OPTIONS
createuser accepts the following command-line arguments: username Specifies the name of the PostgreSQL user to be created. This name must be different from all existing roles in this PostgreSQL installation. -s --superuser The new user will be a superuser. -S --no-superuser The new user will not be a superuser. This is the default. -d --createdb The new user will be allowed to create databases. -D --no-createdb The new user will not be allowed to create databases. This is the default. -r --createrole The new user will be allowed to create new roles (that is, this user will have CREATEROLE privilege). -R --no-createrole The new user will not be allowed to create new roles. This is the default. -l --login The new user will be allowed to log in (that is, the user name can be used as the initial session user identifier). This is the default. -L --no-login The new user will not be allowed to log in. (A role without login privilege is still useful as a means of managing database permis- sions.) -i --inherit The new role will automatically inherit privileges of roles it is a member of. This is the default. -I --no-inherit The new role will not automatically inherit privileges of roles it is a member of. -c number --connection-limit number Set a maximum number of connections for the new user. The default is to set no limit. -P --pwprompt If given, createuser will issue a prompt for the password of the new user. This is not necessary if you do not plan on using pass- word authentication. -E --encrypted Encrypts the user's password stored in the database. If not specified, the default password behavior is used. -N --unencrypted Does not encrypt the user's password stored in the database. If not specified, the default password behavior is used. -e --echo Echo the commands that createuser generates and sends to the server. You will be prompted for a name and other missing information if it is not specified on the command line. createuser also accepts the following command-line arguments for connection parameters: -h host --host host Specifies the host name of the machine on which the server is running. If the value begins with a slash, it is used as the directory for the Unix domain socket. -p port --port port Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. -U username --username username User name to connect as (not the user name to create). -w --no-password Never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a .pgpass file, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password. -W --password Force createuser to prompt for a password (for connecting to the server, not for the password of the new user). This option is never essential, since createuser will automatically prompt for a password if the server demands password authentica- tion. However, createuser will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing -W to avoid the extra connection attempt. ENVIRONMENT
PGHOST PGPORT PGUSER Default connection parameters This utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see in the documentation). DIAGNOSTICS
In case of difficulty, see CREATE ROLE [create_role(7)] and psql(1) for discussions of potential problems and error messages. The database server must be running at the targeted host. Also, any default connection settings and environment variables used by the libpq front-end library will apply. EXAMPLES
To create a user joe on the default database server: $ createuser joe Shall the new role be a superuser? (y/n) n Shall the new role be allowed to create databases? (y/n) n Shall the new role be allowed to create more new roles? (y/n) n To create the same user joe using the server on host eden, port 5000, avoiding the prompts and taking a look at the underlying command: $ createuser -h eden -p 5000 -S -D -R -e joe CREATE ROLE joe NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN; To create the user joe as a superuser, and assign a password immediately: $ createuser -P -s -e joe Enter password for new role: xyzzy Enter it again: xyzzy CREATE ROLE joe PASSWORD 'md5b5f5ba1a423792b526f799ae4eb3d59e' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN; In the above example, the new password isn't actually echoed when typed, but we show what was typed for clarity. As you see, the password is encrypted before it is sent to the client. If the option --unencrypted is used, the password will appear in the echoed command (and pos- sibly also in the server log and elsewhere), so you don't want to use -e in that case, if anyone else can see your screen. SEE ALSO
dropuser(1), CREATE ROLE [create_role(7)] Application 2010-05-14 CREATEUSER(1)
All times are GMT -4. The time now is 07:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy