Sponsored Content
Full Discussion: check the directory exist
Top Forums Shell Programming and Scripting check the directory exist Post 302239028 by Sara-sh on Monday 22nd of September 2008 07:41:56 PM
Old 09-22-2008
Check if a directory exists

Hello:

Can someone please help me figure out what is wrong here, my script does not move on to the "else" part even though there is no .ssh directory on my remote server:

$more putkey.sh
#!/bin/ksh

for server in `cat list`
do
if [ -d /.ssh ]; then
cat $HOME/.ssh/id_rsa.pub |ssh $server ' cat >> .ssh/authorized_keys && echo "key copied"'
else
cat $HOME/.ssh/id_rsa.pub |ssh $server ' mkdir .ssh && cat >> .ssh/authorized_keys && echo "key copied"'
fi
done


$./putkey.sh
Password:
sh: .ssh/authorized_keys: cannot create


The script works if the else part is executed:

$cat $HOME/.ssh/id_rsa.pub |ssh myserver ' mkdir .ssh && cat >> .ssh/authorized_keys && echo "key copied"'
Password:
key copied
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to check if the file exist or not?

say i would like to check if the file is existed before i use rm command. How can i do it? i know if i can use find, but i would like to have a good interface (in a shell script) thks (3 Replies)
Discussion started by: gusla
3 Replies

2. Shell Programming and Scripting

how to check if directory/file exist using c/c++

Hi there,, how to check if directory/file exist using c/c++ under unix/linux? I can use access() under Window MFC. Thanks. Steven (1 Reply)
Discussion started by: steven88
1 Replies

3. Programming

how to check if directory/file exist using c/c++

Hi there, how to check if directory/file exist using c/c++ under linux/unix. Thanks. Steven (2 Replies)
Discussion started by: steven88
2 Replies

4. Shell Programming and Scripting

Check if certain files exist in a directory, if not add name to a textfile

We recieve some logs on our windows box via FTP on a daily basis, in the same directory. I would like to check for missing logs files and add their name to a text file. Something like... Check if C:\logs\file1_currentdate exists (if not, add file1_currentdate to... (1 Reply)
Discussion started by: SunnyK
1 Replies

5. Shell Programming and Scripting

How to check directory exist on servers

There are many servers and their directory structer should be exactly the same. To check the directory path for all servers, I wrote a script. #! /bin/ksh ARRAY_DIRECTORIES="/c/dev/custom/bin" ARRAY_DIRECTORIES="/c/dev/db/custom/src" ARRAY_ENV="remoteName200" ARRAY_ENV="remoteName201"... (2 Replies)
Discussion started by: weonpc
2 Replies

6. Shell Programming and Scripting

To check whether a directory is exist and if it is not, create it

Hi, I want to write a shell script to check whether a directory (say A) is existing in a given location and if it is not, create it. (3 Replies)
Discussion started by: sabya
3 Replies

7. Shell Programming and Scripting

Check if file exist

Hi Does anybody know how I can check if a file exists i.e. see bellow, this doesn't work by the way and if tried countless variations on this file1=$one/file111.txt if then echo "Present" else echo "Not present" fi result : Not present (file is already present, eventhough its... (3 Replies)
Discussion started by: gksenthilkumar
3 Replies

8. Shell Programming and Scripting

Check if file exist

Hi, I am trying to create a bash script which will check if file exist then remove that file else do nothing. I have to do same process for three files in same script. I have written code for one file and trying to run it. if then rm -r /user1/abc/File1 fi When I run this code it... (1 Reply)
Discussion started by: palak08
1 Replies

9. Shell Programming and Scripting

Check if file exist

Hi, I created following script to check if file exist: #!/bin/bash SrcDir=$1 SrcFileName=$2 SrcTimePeriod=$3 if ;then echo 1 else echo 0 fi I ran it like: /apps/Scripts/FileExist.sh /apps/Inbox file1 2nd_period_2010 Even file exist at that location, my above command is... (4 Replies)
Discussion started by: palak08
4 Replies

10. Shell Programming and Scripting

how to check file exist in a directory or not

HI folks, can any one tell me how to check whether the file is existed in a directory or not . let me tell you my requirement : if the file is existed i should display a one message or else i have to send a mail .. i have the mail logic .. but I'm failed to check file existence .. please... (5 Replies)
Discussion started by: sravan008
5 Replies
XOSD(1) 						      General Commands Manual							   XOSD(1)

NAME
osd_cat - X on-screen file displayer SYNOPSIS
osd_cat [OPTION] [FILE]... osd_cat -b percentage|slider [OPTION] DESCRIPTION
Display FILE, or standard input, on X screen. -p, --pos=POS This option tells osd_cat where to display the text. POS can be top, middle, or bottom. The default is top. -o, --offset=OFFSET This option specifies the offset from the top or bottom of screen the text is displayed. The default is 0. -A, --align=ALIGN This option tells osd_cat where to display the text. ALIGN can be left, right or center. The default is left. -i, --indent=OFFSET This option specifies the INDENT from the left of screen the text is displayed. The default is 0. -f, --font=FONT This option specifies the FONT to be used for displaying the text. The default is fixed. -c, --color=COLOR This option specifies the COLOR to be used for displaying the text. The default is red. -d, --delay=TIME This option specifies the number of seconds the text is displayed. The default is 5 seconds. -l, --lines=LINES This option specifies the number of LINES to scroll the display over. The default is 5. -s, --shadow=OFFSET This option specifies the OFFSET of the text shadow. The default is 0, which means no text shadow is created. -S, --shadowcolour=COLOUR This option specifies the COLOUR of the text shadow. The default is black. -O, --outline=WIDTH This option specifies the WIDTH of the text outline. The default is 0, which is no outline. -u, --outlinecolour=COLOUR This option specifies the COLOUR of the text outline. The default is black. -a, --age[=SCROLL_AGE] This option affects screen redrawing. If SCROLL_AGE seconds pass before a new line is ready (for example, you're reading from a pipe), all lines are cleared at once instead of being scrolled off as new lines replace old lines. The default is 0. When no SCROLL_AGE is explicitly given, the current value from DELAY is used. -w, --wait This option also affects screen redrawing. When there is data ready to be put on screen, this option will cause osd_cat to wait until the display is clear. An alternative to scrolling. -b, --barmode=TYPE Lets you display a percentage or slider bar instead of just text. TYPE may be percentage or slider. In this mode no text is read from any file, but the following options can be used: -P, --percentage=PERCENTAGE This option specified the position of the percentage / slider bar. PERCENTAGE may be in the range from 0 to 100, the default is 50. -T, --text=TEXT This option specifies an optional TEXT which gets displayed above the percentage bar. The default is empty, so no additional text is displayed. -h, --help display help (which is often more up to date) and exit With no FILE, or when FILE is -, read standard input. AUTHOR
Martijn van de Streek <martijn@foodfight.org>, Some patching done by Malcolm Valentine <farkit@iprimus.com.au> and Tim Wright <tim@ignavus.net>. xosd was written by Andre Renaud <andre@ignavus.net> and is maintained by Tim Wright <tim@ignavus.net> SEE ALSO
More information on the X OSD Library and its author can be found on http://www.ignavus.net/software.html <http://www.ignavus.net/software.html> COPYRIGHT
It is distributed under the GNU General Public License. X OSD cat January 2001 XOSD(1)
All times are GMT -4. The time now is 12:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy