Sponsored Content
Top Forums Shell Programming and Scripting Script to move .300 extension file from 1 dir to other and email Post 302945844 by sea on Wednesday 3rd of June 2015 04:08:23 PM
Old 06-03-2015
code tags, not icode.

---------- Post updated at 22:08 ---------- Previous update was at 21:21 ----------

Quote:
Originally Posted by sofia8679
when i run the command i donot get the format i wanted.
I am looking for this format
Code:
The following files has been moved from /home/zaree to /home/zaree/test
1. a.beta
2. b.beta

So it is about catching multiple items of with beta extension, and why did you name it 300 extension?

As already been mentioned by wport, make the name-sheme of the actual files, and what is used in the code, the same.

How about:
Code:
#!/usr/bin/env bash
#
#	Variables
#
	shopt -s nullglob #to make `("$src_dir"*.271)` works
	# Dirs
	src_dir="/home/zaree/ " 
	dest_dir="/home/zaree/test/"
	# Files
	err_f="/tmp/error.txt"
	mv_f="/tmp/moved.log" #record moved file in case network down
	# email
	email="zaree@xyz.com"
	replyto="<noreply@xyz.com>"
	BODY=""
	date_string="$(date +'%Y-%m-%d %H:%M:%S')"
	# bools
	dont_move=false
#
#	Preparations
#
	touch "$err_f" "$mv_f"
	if [ ! -d "$src_dir" ] || [ ! -d "$dest_dir" ]
	then	BODY="Error: One or both directory $src_dir/$dest_dir does not exist"
		echo "$BODY" | tee -a "$err_f" 
		dont_move=true
		BODY+"\n"
		#exit 1
	fi
#
#	Get files
#
	if ! $dont_move
	then	files_array=("$src_dir"*.beta)
		for thisFile in "${files_array[@]}"
		do
			mv -f "thisFile" "$dest_dir" 2>>"$err_f"
			if [ 0 -eq $? ]
			then	msg="Successfully moved"
			else	msg="Failed to move"
			fi
			msg="$msg $thisFile"
			echo "$msg" | tee -f $mv_f
			BODY+="$msg\n"
		done
	fi
#
#	Send the mail
#
	echo| mailx -s "$BODY" "$email" 2>>"$err_f"

Hope this helps (hth)
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Move A File With Same Date,don't Change The Desitination Dir Date

Assume, I created one file three years back and I like to move the file to some other directory with the old date (Creation date)? Is it possible? Explain? (1 Reply)
Discussion started by: jee.ku2
1 Replies

2. Shell Programming and Scripting

Help with script, trying to get tcpdump and rotate the file every 300 seconds

Greetings, I just started using scripting languages, im trying to get a tcpdump in a file, change the file name every 5mins ... this is what i have but its not working ... any suggestions? #!/bin/bash # timeout.sh #timestamp format TIMESTAMP=`date -u "+%Y%m%dT%H%M%S"` #tdump =`tcpdump... (3 Replies)
Discussion started by: livewire
3 Replies

3. Shell Programming and Scripting

need to move files of particular day from one dir to another dir

Hi, I have hundered's of files of the name CMP_PORT_IN_P200903271623042437_20090328122430_err.xml in error directory of todays date ie 20090328 and in the file name 5th field specifies date only now i want to move all files of 20090328 to another directory i.e reprocess directory. So... (3 Replies)
Discussion started by: ss_ss
3 Replies

4. Shell Programming and Scripting

Help - Script to move files to subdir depending on file extension.

Hi, First off I'm pretty new to scripting so please be gentle. I am looking for some help with a script that will move all files with a certain extension into a folder within their current location. Just for clarity I have all my photos organised in directories such as: ... (4 Replies)
Discussion started by: guinch
4 Replies

5. Shell Programming and Scripting

Need a script to move the files from one dir to other other dir

Need a script to move the files from one dir to other dir and at the same time it has to read the log in the source dir. Please help me ASAP. (4 Replies)
Discussion started by: viswanathkishor
4 Replies

6. Cybersecurity

Inquiry of .awo hidden dir with bin file inside .eeesync extension

Hi, Me i ask if someone knows about this hidden directory or it me knows where this dir associated with or in a program. I had and notices this .awo dir with bin files inside title 6770669_info.eeesync files in my directory. I wonder if this is associated with my backup program or any program... (0 Replies)
Discussion started by: jao_madn
0 Replies

7. Shell Programming and Scripting

Move all files from dir and subdir to Archive with File name as complete path_filename

HI, I need to move all files from a dir & its all subdir to Archive folder which is indise dir only. and moved filename should changed to complete path ( Like Dir_subdir_subdir2_.._filename ). also all files names shoud capture in a file in order to mail I written below code ... (11 Replies)
Discussion started by: minijain7
11 Replies

8. Shell Programming and Scripting

Script to move all files in a dir into a certain dir

Hello all, I'm very new to shell scripting and need quite urgently to do this thing for my student job. I have a directory called "vectors" with a bunch of files all named ".vector". also i have for each of those files a directory with the name . I now want to move each of those *.vector files... (2 Replies)
Discussion started by: sherresh
2 Replies

9. Shell Programming and Scripting

Remove bad records from file and move them into a file then send those via email

Hi my requirement is that i want pull the bad records from input file and move those records in to a seperate file. that file has to be sent via email.. any suggentions please (1 Reply)
Discussion started by: sxk4999
1 Replies
E2CP(1) 						      General Commands Manual							   E2CP(1)

NAME
e2cp - copies files from/to an e2fs filesystem SYNOPSIS
e2cp [options] files... dest DESCRIPTION
The e2cp command copies files to/from an e2fs filesystem from/to the machine's filesystem. OPTIONS
A single `-' (dash) can be used instead of a file name to indicate standard input/output. -0 Input lines terminated by a null character. -a Absolute directory names - create directories instead of just copying into the destination. Only valid for copying into an ext2fs filesystem. -d dest_dir Destination of files to be copied. May be in the ext2fs filesystem or the host filesystem. -G gid Set the default group to gid. -O uid Set the default file owner to uid. -p Preserve host file attributes (permissions, times, etc.) when copying files. -P mode Set the file permissions (ie 755, 666). -s src_dir The source of the files to be copied. -v Be verbose. SEE ALSO
e2tools(7), e2ln(1), e2ls(1), e2mkdir(1), e2mv(1), e2rm(1), e2tail(1). AUTHOR
The e2tools were written by Keith Sheffield <sheff@pobox.com>. This manual page was written by Lucas Wall <lwall@debian.org>, for the Debian project (but may be used by others). March 2, 2005 E2CP(1)
All times are GMT -4. The time now is 10:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy