Need Help in Cutting a word

Hi All ,

i am working on a backup script , which would a call a executable file in unix server ,

Login credentials ::

use telnet session to login to Unix server

when logged in, this would be my Prompt :::

unix11@raghav:

I just need to cut the word unix11 , so that i can use this to set my path to call the executable ::

Please help me on this

Thanks all for your Help !!!

echo "unix11@raghav" | awk -F"@" '{ print $1}' | read firstword
echo $firstword

Thanks!! but my server name doesnot be constant ..

we use several unix machines. is there any way to cut that part when i login

instead of giving them in echo ???

Thanks!!

well - your prompt could be set to be most anything usually using the PS1 variable - I'm guessing that unix11 is the username you connected as, in which case you could use one of:

id
$USER / $user variable
whoami

etc

to see what your prompt looks like use echo $PS1

(and to answer your question try echo unix11@raghav | sed 's/@.*//' )

 echo unix11@raghav | sed 's/@.*//'
or
 echo unix11@raghav | cut -d@ -f1
or
  echo unix11@raghav | awk -F"@" '{print $1}'

HTH

The PS1 environment variable is how the prompt is defined. Try the echo trick on that variable, or use one of the string operations on the variable - the ones in shell.

What shell?

echo $SHELL

will tell you your shell.

Thanks for your reply

thats not my id , its my server name .. and if i cannot cut those server name is there a possibility to create in link from the source directory to target .

so that when i run the shell script it calls this executable and performs the functions ..

i have only two servers one is unix11 and unix 12 .. in these i have the executables in bin directory . If i create a link in my local directory will that work ???

also let me know how to create a link for a file so that it would be very helpful !!!

Thanks again for your help !!!!

i tried to call the executable by creating a link

ln -s

but it didnot work can anyone let me know how this can be performed!!

Can you try with the below, it will return the Server name(Even if it get change).

uname -n

Thankyou!!! both of my executable is located in the same server .. let say i installed the executable in on location , can it be accessed from a different path using links .. i tried the same but it says "file is not found ""

Thanks!!

you can use a command "uname" on SunOS.

uname -n will display the servername you are logged on.

Eg. abc@server

server_name=`uname -n`
user_name=`echo "user@$server_name" | cut -d"@" -f1`

echo "$user_name $server_name"

OUTPUT:
abc server

Now this can easily be used within a script.

Great Thanks !!!
Is there a way to call a executable by creating a link .. this is the problem which i am right now facing .. if any one help on me on this .. it would great .. because i created a link as well which also didnot work

Thanks again!!!

LINK ------does this mean softlink ? then it works .

Try :
ln -s <absolute_dir_path>/<script_name> <soft_link_name>

Eg:
ln -s sript/to/run/test.ksh myscript

and then you can directly call "myscript" from command line to run the script.

Is this what you were looking for .

Thanks it worked !!!!