See if file exists and if not create it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting See if file exists and if not create it
# 1  
Old 03-16-2015
See if file exists and if not create it

Hi,
I am using an expect script to roll out an ssh key to multiple servers. I have a problem as on some of them the authorized_keys file exists and on some it doesn't. Where it exists I need to >> the key in and where it doesn't I need to create the file then sftp the file over.
So I need some help ! Is there a simple script using a 'for' loop which I can use to login to mutltiple server and check if a file exists (and if not create it?)
As usual any help much appreciated

Cheers
G
# 2  
Old 03-16-2015
You should be able to append on every server. If the file doesn't exist, it will create it. You really then only need to be sure of setting the permissions correctly for the key to be considered as secure and allow the various commands to work.



Robin
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 03-16-2015
Also look at "ssh-copy-id".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Mkdir a/b/c # where a/b does not exists. is it possible to create it ?

Is is possible to create the directories in following manner. for example my home dir is empty and i want to create dir a/b/c mkdir a/b/c # where a/b does not exists. (5 Replies)
Discussion started by: anandgodse
5 Replies

2. Shell Programming and Scripting

how to check if a directory exists or not.if not need to create it

Hi, I am using solaris 10 OS and bash shell.just checking for small code snippet which follows below. /export/home/vomappservers/spa/common/5.0 /export/home/vomappservers/spa/common/scripts /export/home/vomappservers/spa/tools /export/home/vomappservers/spa/scm5.0/SCCS... (5 Replies)
Discussion started by: muraliinfy04
5 Replies

3. Shell Programming and Scripting

File exists, but cannot be opened.How to check- whether it could be opened to read when it exists

Hi #Testing for file existence if ; then echo 'SCHOOL data is available for processing' else echo 'SCHOOL DATA IS NOT AVAILABLE FOR PROCESSING' : i wrote a script, where it begins by checking if file exists or not. If it exists, it truncates the database... (2 Replies)
Discussion started by: rxg
2 Replies

4. Windows & DOS: Issues & Discussions

Script that, if file exists in Samba share, moves file to Unix server

I'm looking to do pretty much what the title says. I want a script that runs, it can run on Unix or Windows, doesn't matter, and searches a Samba shares for a .txt file. If the file exists, the script will move (or possibly copy) the file from the Samba share into a directory on our Unix... (3 Replies)
Discussion started by: twcostello
3 Replies

5. Shell Programming and Scripting

Script to check for the file existence, if file exists it should echo the no of modified days

Hi, I am looking for a shell script with the following. 1. It should check whether a particular file exists in a location #!/bin/sh if ; then echo "xxx.txt File Exists" else echo "File Not Found" fi 2. If file exists, it should check for the modified date and run a command... (2 Replies)
Discussion started by: karthikeyan_mac
2 Replies

6. Shell Programming and Scripting

Newbie.. Find if a file exists and open, if not create the desired file..

Hey all, I'm brand new to script writing, I'm wanting to make a script that will ask for a file and then retrieve that file if it exists, and if it doesn't exist, create the file with the desired name, and I'm completely stuck.. so far.. #! bin/bash echo "Enter desired file" read "$file" if ... (5 Replies)
Discussion started by: Byrang
5 Replies

7. UNIX for Dummies Questions & Answers

Check if file exists, and create file

hi i have 2 questions: 1. how can i check if file exist in vi? i tryed to do: if ; then echo file exist but i get from the compiler if: Expression Syntax. 2. how can i create file in vi? when im using cat - so the script stop and wait for me to write somthing into the new file when im... (2 Replies)
Discussion started by: nirnir26
2 Replies

8. Shell Programming and Scripting

Check if file exists, create new file?

Hi everyone, I'm brand new to shell scripts (and UNIX in general) and I've been able to figure everything out except this... I want to write a script that will take a filename as an argument, append the date to it (IE Dec 24 2008) and make sure it doesn't already exist, if so, add an integer to... (4 Replies)
Discussion started by: solarnoise
4 Replies

9. Shell Programming and Scripting

Need to write a script in UNIX to find a file if another file exists

So I have a lot of Java applications on my servers all having their own folder from the applications subdirectory. Now, I need to do the following. Search all the applications subdirectories for message.jar. If the message.jar file exists, I need to search the application directory for... (1 Reply)
Discussion started by: mmdawg
1 Replies

10. Shell Programming and Scripting

Check File Exists and compare to previous day file script

We have data files that are ftp'd every morning to a SUN server. The file names are exactly the same except for that each has the date included in its name. I have to write script to do 2 things: STEP 1) Verify that the file arrived in morning. STEP 2) Compare the file size of the current... (3 Replies)
Discussion started by: rbknisely
3 Replies
Login or Register to Ask a Question