Sponsored Content
Top Forums Shell Programming and Scripting Optimizing the Shell Script [Expert Advise Needed] Post 303007854 by MadeInGermany on Wednesday 22nd of November 2017 03:11:45 PM
Old 11-22-2017
If the long runtime is caused by the many files that find needs to traverse then there is hardly anything that can be done.
But maybe it is due to a misbehavior of a special character.
The following is a bit safer, and contains some further optimizations, like using a filedescriptor for logging rather than open-append-close each time, and sorting on key field 1 only, ...
Code:
#!/bin/bash
PATH=/bin:/usr/bin:/usr/sbin:/sbin
NOW=$(date +"%F-%H:%M:%S")
LOGFILE="purge_duplicate_log-$NOW.log"
LOGTIME=`date "+%Y-%m-%d %H:%M:%S"`
cd /tmp/sathish/GB/ || exit
mkdir -p dup || exit
echo "$LOGFILE"
exec 3>>"$LOGFILE" # open it once, the shell will close it at exit
echo "Started at $LOGTIME " >&3
echo "Before File Count " >&3
ls | wc -l >&3
dups=$(find . -type f \( -iname "*.xml" \) -printf '%T@ %p\n' | sort -rg -k 1,1 | sed 's/[^ ]* //' | awk -F"_" 'dup[$1]++')
if [ -z "$dups" ]
then
  echo "No Duplicates Identified" >&3
else
  set -f # no wildcard globbing, only word splitting
  for i in $dups
  do
    mv -vf "$i" dup/
  done >&3 2>&1
  set +f
fi
echo "Ended at $LOGTIME " >&3
echo "After File Count " >&3
ls | wc -l >&3

 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script help needed

I am trying to query a table having 3 columns, the third column is a field of varchar(1024) with a SQL string in it. I am using cut command to split out the three fields into three variables. I do a db2 command to extract the data into a file. My problem is with the third field having the SQL... (3 Replies)
Discussion started by: fastgoon
3 Replies

2. Shell Programming and Scripting

mail program on shell script didn't work, please advise.

Hi, everyone: I post a new thread because previous post may sink and I hope the new one can be caught by your eyes. I created a shell script and the script works fine. However, the mail program part on script didn't send email to my email box and it also didn't provide any traceable... (7 Replies)
Discussion started by: duke0001
7 Replies

3. Shell Programming and Scripting

Need help optimizing this piece of code (Shell script Busybox)

I am looking for suggestions on how I could possibly optimized that piece of code where most of the time is spend on this script. In a nutshell this is a script that creates an xml file(s) based on certain criteria that will be used by a movie jukebox. Example of data: $SORTEDTMP= it is a... (16 Replies)
Discussion started by: snappy46
16 Replies

4. Shell Programming and Scripting

Need some expert advise on running scripts.

We have couple of scripts made for our environment (which is Oracle Virtulisation ) . Each script is assigned a different task . Some of the scripts are meant to run on centralized server for monitoring other Servers resource utilization such as CPU,Storage. While some are meant to run on... (6 Replies)
Discussion started by: pinga123
6 Replies

5. UNIX for Advanced & Expert Users

os x hdiutil expert needed

I am writing a script that using the "Total Bytes" field from hdiutil imageinfo -plist <file>. My intention is to get the total mounted size of a compressed dmg. It works for some images, but sometimes it doesn't seem to match up, particularly with larger (over 1 gb) images. Can anybody explain... (10 Replies)
Discussion started by: nextyoyoma
10 Replies

6. Shell Programming and Scripting

fgrep command: Perl programming help needed..Kindly advise

Hi, I am novice in PERL enviornment. I have a text files withso many entries in rows and columns. I have to pick up entries named as "Uniprot ID" in the file and create a new text file with list of particular Uniprot ID entries. Can anybody guide regarding this.. I came to know abut fgrep... (1 Reply)
Discussion started by: manigrover
1 Replies

7. Shell Programming and Scripting

How to expert Shell Programming ?

Guys, I have been reading the bash books, there are so many command & operators etc. The theory part is so much. Overall I have read some book. Still do not feel I know the bash with confidence. Lots of Jobs for System Admin demand Scripting knowledge as requirement .. I think I should... (7 Replies)
Discussion started by: heman96
7 Replies

8. Shell Programming and Scripting

Portable shell script advise

All, I have a need for a portable shell script for LInux and HPUX. The script has a simple need; Check for local files of a specific name (i.e. filename*), scp them to another system, and archive them to a folder. The script runs via cron. I first wrote the script in Linux (bash with gnu... (4 Replies)
Discussion started by: hburnswell
4 Replies
SCRIPT(1)							   User Commands							 SCRIPT(1)

NAME
script -- make typescript of terminal session SYNOPSIS
script [-a] [-c command] [-e] [-f] [-q] [-t[=file]] [-V] [-h] [file] DESCRIPTION
script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1). If the argument file is given, script saves all dialogue in file. If no file name is given, the typescript is saved in the file typescript. Options: -a, --append Append the output to file or typescript, retaining the prior contents. -c, --command command Run the command rather than an interactive shell. This makes it easy for a script to capture the output of a program that behaves differently when its stdout is not a tty. -e, --return Return the exit code of the child process. Uses the same format as bash termination on signal termination exit code is 128+n. -f, --flush Flush output after each write. This is nice for telecooperation: one person does `mkfifo foo; script -f foo', and another can super- vise real-time what is being done using `cat foo'. --force Allow the default output destination, i.e. the typescript file, to be a hard or symbolic link. The command will follow a symbolic link. -q, --quiet Be quiet. -t, --timing[=file] Output timing data to standard error, or to file when given. This data contains two fields, separated by a space. The first field indicates how much time elapsed since the previous output. The second field indicates how many characters were output this time. This information can be used to replay typescripts with realistic typing and output delays. -V, --version Output version information and exit. -h, --help Output help and exit. The script ends when the forked shell exits (a control-D to exit the Bourne shell (sh(1)), and exit, logout or control-d (if ignoreeof is not set) for the C-shell, csh(1)). Certain interactive commands, such as vi(1), create garbage in the typescript file. Script works best with commands that do not manipulate the screen, the results are meant to emulate a hardcopy terminal. ENVIRONMENT
The following environment variable is utilized by script: SHELL If the variable SHELL exists, the shell forked by script will be that shell. If SHELL is not set, the Bourne shell is assumed. (Most shells set this variable automatically). SEE ALSO
csh(1) (for the history mechanism), scriptreplay(1). HISTORY
The script command appeared in 3.0BSD. BUGS
Script places everything in the log file, including linefeeds and backspaces. This is not what the naive user expects. AVAILABILITY
The script command is part of the util-linux package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/. util-linux February 2011 util-linux
All times are GMT -4. The time now is 12:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy