Newbie needs Help with reading files into..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Newbie needs Help with reading files into..
# 1  
Old 06-22-2018
Newbie needs Help with reading files into scp path

Hello All,

im a newbie in scripting and i need some help

i need a script for reading some files into varibles.

Background

i want to do an

Code:
scp localmaschine/localpath/$nameoffile.xml user@server:/path/$nameoffile/*/$nameoffile.xml

i got 20 - 30 files with diferent names i cant change the path and i have to copy it

it would very cool if someone can help me

Last edited by vbe; 06-22-2018 at 04:06 PM.. Reason: code tags not HTML, thanks
# 2  
Old 06-22-2018
Would a simple loop not suffice?
# 3  
Old 06-22-2018
maybe?
if its possible? i got one sourcedir with all .xml files on my localhost and i have upload all files to server:/basedir/filenamefolder/filename.xml

The way does not matter
# 4  
Old 06-22-2018
something like
Code:
for FILE in $(ls "sourcedir")
do
   scp localpath/$FILE.xml user@server:/path/$FILE/$FILE.xml
done

This is for ksh...
# 5  
Old 06-22-2018
that looks good
thanks mate

---------- Post updated at 02:54 PM ---------- Previous update was at 02:51 PM ----------

but on ls he maybe will pickup the .xml too?

---------- Post updated at 03:47 PM ---------- Previous update was at 02:54 PM ----------

also something like that but only working xD

Code:
echo Enter your local directory
read localdir

for FILE in $(ls -1 | cut -d. -f1 "$localdir"); do scp $localdir/$FILE.xml user@server:/path/$FILE/$FILE.xml

# 6  
Old 06-22-2018
if your source directory contains ONLY the .xml files, you can copy the entire directory over recursively:
Code:
echo Enter your local directory
read localdir

scp  -r "${localdir}" user@server:/remoteDirPath

# 7  
Old 06-22-2018
@vgersh99 nope that didnt work cause i need the file name for the fully remoteDirpath
$(ls -1 | cut -d. -f1 "$localdir")

---------- Post updated at 07:00 PM ---------- Previous update was at 04:56 PM ----------

ok i got it
for FILE in $(ls -1 "$localdir" | cut -d. -f1 | grep -E '^[A*]'); do scp $localdir$FILE.xml $user@servername:$FILE/$FILE.xml; done

---------- Post updated at 07:19 PM ---------- Previous update was at 07:00 PM ----------

Ok next question xD

Code:
         
if check_file test.sh; then
         echo "File exists"
         else
         echo "
         #!/bin/bash

         SOURCEDIR=${manifest}
         if [ -z "$STY" ]; then exec screen -dm -S 'test Import' /bin/bash "$0"; fi
         for i in *; do id=$(echo ${i} | cut -d'_' -f1 | cut -c 2- ); extid=00${id}; /root/test_dir/other_test_file.pl -b ${SOURCEDIR} -m ${extid} -v 2>&1 | tee /root/test_dir/${extid}.log ; done " >> test.sh
         echo created test-Importer
         fi

i want to write this file
but i only want to fill this Varible on the script

Code:
SOURCEDIR=${manifest}

the other variables i want to fill later if i running the new created file on server
but if i use this all Variables been removed after creating file

and it looks like that
Code:
         #!/bin/bash

         SOURCEDIR=/mnt/f/test5/
         if [ -z  ]; then exec screen -dm -S 'test Import' /bin/bash ./menu.sh; fi
         for i in *; do id=; extid=00; /root/test_import/other_test_file.pl -b  -m  -v 2>&1 | tee /root/test_import/.log ; done

but i need it like that

Code:
 #!/bin/bash
         SOURCEDIR=/mnt/f/test5/
         if [ -z "$STY" ]; then exec screen -dm -S 'test Import' /bin/bash "$0"; fi
         for i in *; do id=$(echo ${i} | cut -d'_' -f1 | cut -c 2- ); extid=00${id}; /root/test_dir/other_test_file.pl -b ${SOURCEDIR} -m ${extid} -v 2>&1 | tee /root/test_dir/${extid}.log ; done " >> test.sh
         echo created test-Importer
         fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need Help in reading N days files from a Directory & combining the files

Hi All, Request your expertise in tackling one requirement in my project,(i dont have much expertise in Shell Scripting). The requirement is as below, 1) We store the last run date of a process in a file. When the batch run the next time, it should read this file, get the last run date from... (1 Reply)
Discussion started by: dsfreddie
1 Replies

2. Programming

need help with shell script filtering files and sort! newbie question?

Hi folks, I would like to get familiar with shell script programing. The first task is: write a shell script that: scans your home-folder + sub-directory for all txt-files that all users of your group are allowed to read and write then output these files sorted by date of last... (4 Replies)
Discussion started by: rollinator
4 Replies

3. Programming

help with opening files and reading them in C

In C, given a name or path to a file, how do I check if the path is valid, and how can I check its permisions will let me read from it, and how do i check if its an empty file? (15 Replies)
Discussion started by: omega666
15 Replies

4. Solaris

Newbie questions about HOME directory files

Hi, I am newbie to Solaris and system administration in general, and I have a couple of questions about files in my HOME directory. When I perform ls -la, I get the following list of files: drwxr-xr-x 7 XXXYYY staff 17 Aug 24 07:31 . drwxr-xr-x 7 root root 7... (2 Replies)
Discussion started by: JVerstry
2 Replies

5. Shell Programming and Scripting

reading from 2 files using awk

hi, Is it possible to read and compare 2 files which have different Field separators at the same time using awk??? file1: 1,dayal,maruti,Z-234,bangalore,KA,........ 2,yash,esteem,Y-007,delhi,DL,........... . . . fill 2: Z-234|Registered|Bangalore Y-007|Registered|Bangalore . . . ... (2 Replies)
Discussion started by: VGR
2 Replies

6. UNIX for Dummies Questions & Answers

UNIX newbie NEWBIE question!

Hello everyone, Just started UNIX today! In our school we use solaris. I just want to know how do I setup Solaris 10 not the GUI one, the one where you have to type the commands like ECHO, ls, pwd, etc... I have windows xp and I also have vmware. I hope I am not missing anything! :p (4 Replies)
Discussion started by: Hanamachi
4 Replies

7. Shell Programming and Scripting

reading two files

Hi, I have 2 files file 1 ---- 10013 This is a text 10014 This is a test 10015 This is a temp file 2 ---- 10013 010014737 ADSM 1300004 E 10014 020012323 ABCD 1718888 E 10015 030121212 ADSW 1290991 E need to compare column1 in... (2 Replies)
Discussion started by: injeti
2 Replies

8. Solaris

Reading Files In

I'm looking to write a script where i look in a file called files.txt. This file has a list of other files in there. I want the script to be able to look at this files.txt and go off and find the files that are listed in another directory. I am doing it this way as filenames change week in... (1 Reply)
Discussion started by: Pablo_beezo
1 Replies

9. UNIX for Dummies Questions & Answers

Reading Files

Hi I need to perform certain tests on information contained in a file, a lot of what is contained in the file is duplicate data, so what I want to do as it is a failrly substantial file size is to start and finish reading from a specifed line in the file. Can someone tell me how to indicate... (3 Replies)
Discussion started by: oop
3 Replies

10. Shell Programming and Scripting

reading gz files

Hi, I have a simple perl script where I am passing array of gziped files to the while loop and trying to read content of each field one line at the time using gzcat. Yet, I can not get it to work Here is what I am doing ... while ($filename=shift) { open(MYFILE, "| gzcat $filename"); ... (2 Replies)
Discussion started by: arushunter
2 Replies
Login or Register to Ask a Question