Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Thursday, April 10, 2014

File transer/FTP files from Linux box to AS400 system.

Rather than going through the trouble of writing programs using third party utilities to ftp (file transfer protocol) files, the below simple shell script will do the job.

ls -t /home/temp/abc*.txt | head -1
The above linux command is to get the most recent file. You can change the file pattern to anything you like.

TEMPFILE01
This is the destination file that will be created.


#!/bin/sh
HOST=myserver.test.com
USER=username1
PASSWD=password1
SRC_FILE="$(ls -t /home/temp/abc*.txt | head -1)"
FILE=TEMPFILE01

echo $SRC_FILE

ftp -nu $HOST <user $USER $PASSWD
put $SRC_FILE $FILE
quit
exit 0
End-Of-Session

x

Thursday, August 23, 2012

copy select files recursively in linux


In Linux to recursively copy select files within a directory structure to a destination folder (without maintaining the source directory structure) use the below command,

find . -name '*tests.txt' -exec cp {} /myprojects/myfiles \;

note: the '\;' is needed by the exec command 

Wednesday, April 25, 2012

Run shell script as sudo user in Linux

To run a shell script as a sudo user in Linux can be achieved using the -s option of the sudo command.



sudo -u user123 -s /home/myscripts/runtest1.sh

will execute the runtest1.sh script using user user123