sh,ksh,aix , error to delete files older than 1 day form csv list

error to delete files older than 1 day form csv list


Tag: sh,ksh,aix

I want to delete files in a directory, from the supplies csv file if its older than 1 day.

I tried to print them for test purpose:




 while IFS=',' read -r id name
   find tmp/$name -mtime +1 -type f
 done < "$INPUT"

Ths code throws error :

find: bad status-- tmp/one
find: bad status-- tmp/two



recall that the form for a find command is

 find ${baseDir} -${options ......} args to opts.

Your form is saying

find tmp/$name -mtime +1 -type f
# --^^^^^^^^^^ -- start looking in dir tmp/$name

You probably want to say

find tmp -name $name -mtime +1 -type f
#---^^^^^ start looking in the tmp dir

Keeping the -type f may not be needed, but it prevents you from matching a directory instead of a file.



loop through different arguments in Rscript within Korn shell

I have an R script which I'm running in the terminal by firstly generating a .ksh file called myscript.ksh with the following information: #!/bin/ksh Rscript myscript.R 'Input1' and then run the function with ./mycode.ksh which sends the script to a node on the cluster in our department (the processes that...

storing sql result into an ksh array

I wrote a teradata query function that returns results which I can easily store into a variable when it returns one column. But now I want to return more than one column and store that into an array (I assume) so that I can run compare operations on the 2nd...

source: not found error while running shell script on ubuntu 14.04

OS- Ubuntu 14.04 This is my shell script which i want to schedule using cron job. #!/bin/bash source .profile workon venv cd /home/ashish/deployments/myproject export DJANGO_SETTINGS_MODULE=myproject.settings_production python /home/ashish/deployments/myproject/myproject/ parse_data Cron job- */15 * * * * . /home/ashish/ Whenever this cron job runs i receive a mail with errors: /bin/sh:...

How to append entry the end of a multi-line entry using any of stream editors like sed or awk

I am trying to use a script to append the host name at the end of a multi-line entry of a specific Host_Alias field in sudoers file. The current sudoers file has an entry similar to : Host_Alias srv_linuxestate= \ host10,host12,host13,host1,host50,\ host16,host1,host2,host11,host15,host21,\ host3,host14 My required output would be something like...

How can `time` control other processes trough a pipe?

In the general case we have a command like P | Q | R which has the following semantics for the shell: Create a processes P, Q, R Bind the output of P to the input of Q Bind the output of Q to the input of R Bind the...

Syntax error: “fi” unexpected (expecting “then”) in bash script

I try to do the script: #!/bin/bash IP='' fping -c1 -t300 $IP 2>/dev/null 1>/dev/null if [ "$?" = 0 ] then echo "Host found" else echo "Host not found" fi and i turn it: [email protected] ~ $ sh /home/pi/sh/ /home/pi/sh/ 9: /home/pi/sh/ Syntax error: "fi" unexpected (expecting "then") where is...

Get value of variable with the aggregated values of other variables [duplicate]

This question already has an answer here: Bash, Concatenating 2 strings to reference a 3rd variable 2 answers Given: export A='TEST_' export B='VAR' How would I get the value of $TEST_VAR in this case? Some more conditions: should work both on sh and bash of the latest versions. should...

Issues with Screen - Running Minecraft in a while loop through a screen session

So Earlier today, I changed my startup scripts for my minecraft server. Problem is, after about 3 hours, the screen for it that was open vanished and refuses to appear when using -ls. The server is still running and from what I can see below, the screen process should still...

Last run time of shell script?

I need to create some sort of fail safe in one of my scripts, to prevent it from being re-executed immediately after failure. Typically when a script fails, our support team reruns the script using a 3rd party tool. Which is usually ok, but it should not happen for this...

sh script vulnerability in Linux

I was given an assignment for my Computer Security class. We we were given a piece of code to analyze and determine the vulnerabilities that it might have. #!/bin/sh # shell script to create a copy of the shadow file to the /tmp directory echo > /tmp/shadowcopy # allow only...

Redirect stdout using exec in subscript

I have one main script which is started as an service. I can't modify this main script, because it is often updated. This main script starts a program, which echo any log to stdout. So i can't see any log of this program. But this main script calls at the...

Arguments with spaces are seen as separate arguments and not as one argument [duplicate]

This question already has an answer here: Handle whitespaces in arguments to a bash script 3 answers I have the following functions func() { shift 2; func2 [email protected]; } func2() { echo $1; echo $2; } func 1 2 "3 3" "4 4" I exepect that func2 will dispaly...

Showing progress as shell script runs

I would like to display something showing that the script is still gathering information from a device. Whether it be hash marks or periods. As you can see below when it starts its walk of a device it echos its start time. It is here I would like to show...

Storing data in shell

I have a need to store a list of e-mails in a shell script. This script will get called and passed a customer number. depending on the customer number I want to populate a variable based on the passed in customer number. I am not sure how to accomplish this...

Environmental variable is empty into shell script but not in shell

A shell script checks some of my environmental variables, but this code: if [ -z "$ANDROID_NDK" -o -z "$ANDROID_SDK" ]; then echo "You must define ANDROID_NDK, ANDROID_SDK before starting." echo "They must point to your NDK and SDK directories.\n" exit 1 fi prints out You must define ANDROID_NDK, ANDROID_SDK before...

SIGHUP signal handler reset to default when using system() on embedded linux with busybox

I am working on an embedded linux with busybox. As part of my application I have a rc.init script E80-startmyprog. That script is calling my program prog. trap "" HUP startmyprog >${LOGFILE} 2>&1 </dev/null & startmyprog() { prog } In my program I can see that the signal handlers are...

Printing a newline

GAAAAAAAAAAAAAAH I don't know why I'm struggling so much with this. All I want to do is make: file="$a"[command-here]"$b" to make $file= a [newline] b And yet no matter WHAT echo or printf I try to use, I cannot get it to work!! I just want a newline between a...

How to write and match regular expressions in /bin/sh script?

I am writing a shell script for a limited unix-based microkernel which doesn't have bash! the /bin/sh can't run the following lines for some reasons. if [[ `uname` =~ (QNX|qnx) ]]; then read -p "what is the dev prefix to use? " dev_prefix if [[ $dev_prefix =~ ^[a-z0-9_-][email protected][a-z0-9_-"."]+:.*$ ]]; then...

Bash script - Auto fill answer

I have a bash script that has several questions, is it possible to automatically fill the answers ? ./ install answers in order y 2 1 n n How can I do that in bash ? edit: is it possible to only pass the first answer ? echo "y" |...

How to split and iterate substrings by delimiter in BOURNE SHELL?

Recently I've been trying to customize my shell profile located at ~/.profile in Ubuntu. One thing I want to do is: # PATH-like variable containing paths separated by ':' MY_ROOTS=/f/o/o:/b/a/r:/e/t/c for some magic iterating my_root in $MY_ROOTS do; my_bin="$my_root/bin" # add it to PATH! [ -d "$my_bin" ] && {...

Pipe that does nothing

I'm on a AIX box and need a program that when used after a pipe does nothing. I'll be more exact. I need something like this: if [ $NOSORT ] ; then SORTEXEC="/usr/bin/doesnothing" else SORTEXEC="/usr/bin/sort -u" fi # BIG WHILE HERE do done | SORTEXEC I tried to use tee...

How to do the expansion of variable in shell script? [duplicate]

This question already has an answer here: Bash expand variable in a variable 4 answers I hava a column in database which contains the following data: sql_proc|test_sql.sql|/home/Desktop/myfile.txt|$IMP_FILES/myFolder|convert I have fetched this into a variable and I have used the cut command with "|" as delimiter and saved each field...

Split comma separated list, sort and compare - output the difference - KSH

I'm working on a problem in KSH, and need to take two comma separated lists and compare them, then output the differences. Example input 1: apple, banana Example input 2: apple, banana, kiwi Output: kiwi I assume I will need to put the lists into arrays and compare each string...

Can I use grep in place of awk?

I'm attempting to take this output (linebreak added for readability, please discard on reading): mCurrentFocus=Window{167ead2f u0} and extract this: using only the tools natively available in Android, such as grep. The following commands will do it, but they use cut rev and awk. dumpsys window windows | grep...

How can I detect if some file in a subdir changed?

Basically I have a big directory (>10GB)(each subdir only has a few other subdirs) and want to do sth to any files that changes. I can't just go through all the files and check, because it takes to long and uses about 90% of my CPU :(. This is how...

shell command to skip file in sequence

I run a C++ code for several data files in sequence using: for i in $(seq 0 100); do ./f.out c2.$(($i*40+495)).bin `c2.avg.$(($i*40+495)).txt; done` Now if some input files are missing, say c2.575.bin is missing then the command is not executed for the rest of the files. How could I modify...

Sort and counting a column without uniq in bash

I want to add a count of only the first column using bash, without doing uniq, like this: input: 58311s2727 NC_000082.6 100.00 50 58311s2727 NC_000083.6 100.00 60 58311s2727 NC_000084.6 100.00 70 58310s2691 NC_000080.6 100.00 30 58310s2691 NC_000081.6 100.00 20 58308s2441 NC_000074.6 100.00 50 output: 3 58311s2727 NC_000082.6 100.00 50 3...

Why doesn't ${#$2} work?

I have this line in a small bash function: if [ ${#$2} -lt 25 ]; then But it gives me Bad substitution on the ${#$2}. What am I doing wrong there? I'm trying to get the length in characters of the second command line argument. How can I do this?...

how to deletes line from a text file that are taken from another file [duplicate]

This question already has an answer here: Remove duplicates from text file based on second text file 4 answers I have a data.txt file with a lot of lines in it and a lines.txt that contains some lines. I want to delete all lines from data.txt that match any...

Linux - sh script - download multiple files from FTP

I need script that can download files from ftp via my sh code I have use expect with ftp, but if I do for loop inside code, I got wrong # args: should be "for start test next command" while executing "for v in "a b c"" My code /usr/bin/expect...

Linux shell file. mkdir and pushd commands not doing what I'd like

I'm trying to create a directory if it does not exist, and the further down the line, create a log file in that directory. It would be in the current users home directory In pseudocode: If directory "/home/LOGS" does not exist make directory "/home/LOGS" Then whenever a log file is...

Monitor Process and echo if taking too long

I have a script that monitors a Process and display (flashes) "..Please Wait.." while the Process is in progress Then returns "...Process complete" once the Process is done. How can I terminate the monitoring and Output something like "Timeout" if The process is more than, say, 120 seconds. - without...

How can I run a docker container and commit the changes once a script completes?

I want to set up a cron job to run a set of commands inside a docker container and then commit the changes to the docker image. I'm able to run the container as a daemon and get the container ID using this command: CONTAINER_ID=$(sudo docker run -d my-image /bin/sh...

How to limit the CPU usage of a dash loop that listens for a filesystem change?

I wrote a loop in dash which waits for a file to appear in a certain location on the filesystem. But when it runs it takes up 50% of the CPU. I first lowered the CPU usage using a sleep command but the minimal sleep time in dash (1 second)...

How do I parse the output of a command into columns using awk and grep

I have the output of pkginfo -l that looks like below A: aaa1 B: bbb1 C: ccc1 D: ddd1 A: aaa2 B: bbb2 C: ccc2 D: ddd2 A: aaa3 C: ccc3 D: ddd3 I want this output translated into columns such that it looks like below A B C D...

Validating file records shell script

I have a file with content as follows and want to validate the content as 1.I have entries of rec$NUM and this field should be repeated 7 times only. for example I have rec1.any_attribute this rec1 should come only 7 times in whole file. 2.I need validating script for this....

Increment of multiple file prefixes?

I am looking for a way in Bash to rename my file prefixes. These files are all in one folder. No other files will be in it. 00 - Artist - Title.mp3 01 - Artist - Title.mp3 ... and so on to 01 - Artist - Title.mp3 02 - Artist...

ANSI escapes don't work in `printf`

When trying to use ANSI color escapes from a shell script, I was completely stuck, as the escape sequences (\e) were printed verbatim to the output. #!/bin/sh GREEN="\e[32m" RED="\e[31m" CLEAR="\e[0m" printf "${GREEN}test passed${CLEAR}\n" printf "${RED}test failed${CLEAR}\n" Produces \e[32mtest passed\e[0m \e[31mtest failed\e[0m ...

Getting duplicate output

I'm trying to write a bash script that looks for a file in one directory and replaces it with one of the same name from a source directory. When I run the find command, it seems to be setting my $path twice for f in build-res/$1/*.png; do file="$(basename "$f")" echo...

How to execute command when df -h return 98% full

How to execute command when df -h return 98% full I have a disk which is by the /dev/sdb1 917G 816G 55G 94% /disk1 If its return 98% full, I would like to do the following find . -size +80M -delete How do I do it, I will run the...

Sanitize the different formats of CSV-formatted phone numbers

Suppose there are several different kinds of CSV-formatted telephone numbers as follows: Here is the first CSV file with lines as follows: "Name","Address","FullPhone" "Mike Wise","101 Abc Drive","4061234567" // Need to separate area code from the rest Here is another CSV file with lines as follows: "Name","Address","Areacode","Phone" "Mike Wise","101 Abc Drive","406","123-4567"...

Where does the recursive variable expansion in bash/shell numeric contexts come from?

The POSIX spec states with regard to Arithmetic Expansion that [i]f the shell variable x contains a value that forms a valid integer constant, optionally including a leading plus or minus sign, then the arithmetic expansions "$((x))" and "$(($x))" shall return the same value. Which is a reasonable shortcut and...

Getting value from function, use that value to get colored output in shell

(Using zsh) I am just trying to get random color output whenever I open a new tab in my terminal. To achieve this I wrote the following shell script, but it is not working as expected: #Standard Colors red='\033[0;31m' NC='\033[0m' # No Color black='\033[0;30m' blue='\033[0;34m' green='\033[0;32m' cyan='\033[0;36m' purple='\033[0;35m' yellow='\033[1;33m' lgreen='\033[1;32m'...

How to extract value of root variable from kernel commandline

I want to extract the value set to the root variable in following kernel command line, I don't want to use awk column number. console=ttyO0,115200n8 noinitrd mem=256M root=/dev/mmcblk0p2 rw rootfstype=ext4 rootwait=1 ip=none I am able extract it using following command but it depends on the position of root variable but...

Why does Scala use a reversed shebang (!#) instead of just setting interpreter to scala

The scala documentation shows that the way to create a scala script is like this: #!/bin/sh exec scala "$0" "[email protected]" !# /* Script here */ I know that this executes scala with the name of the script file and the arguments passed to it, and that the scala command apparently...

Disregard word order when comparing two variables

I want to compare two variables using shell. $a="abc pqr mno xyz" $b="mno pqr xyz abc" Here two variable values are same (just words order is not same inside the variable). If i compare $a and $b it will say that $a and $b are not same, but I want...

Using awk and grep command in for loop

Consider below code snippet: #! /bin/ksh for i in `grep "ProcessOrderWebService-N" Orders.Log | grep "::stringFromNetwork = 600001" | awk -F',' '{print $1}'`; do echo $i; done; 2015-05-26 10:20:10 2015-05-26 10:20:49 2015-05-26 10:21:45 From the command prompt, when I run the command: grep "ProcessOrderWebService-N" Orders.Log | grep "::stringFromNetwork = 600001" |...

String comparison in ksh never succeeding

I have the next script, and when trying to compare variable value if equals "NO" or "SI" (yes in spanish) it's not working for some reason I keep going all the time through the else (SI) although the real value in the variable is "NO". It's even being printed in...

POSIX Shell backslash confusion

I am trying to create a shell script with a simple functionality, but it seems I can not wrap my head about how to handle backslashes correctly. One of my functions look like this: #!/bin/sh func() { cmd="$*" printf "%s\n" "$cmd" echo -e $cmd } func '%{NAME}\\n' This is the...