Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (2)

3
votes
3answers
153 views

Bash script command line argument to upper case

If I can do this in my bash shell: $ STRING="A String" $ echo ${STRING^^} A STRING How can I change my command line argument to upper case? I tried: GUARD=${1^^} This line produces Bad ...
0
votes
2answers
38 views

Auto Delete Inactive files after x

Is there a way I could delete certain folders after x amount of days of inactivity? I was thinking of using cron but that wouldn't take the inactivity part into consideration. Is there any Debian ...
1
vote
2answers
45 views

I cannot understand bash script results

Here is the script: echo '1 2 3 4 5 6' | while read a b c ;do echo result: $c $b $a; done The result is 3 4 5 6 2 1 Can someone explain why?
0
votes
0answers
19 views

check media resolution if resolution is big ffmpeg it, if output is smaller than original delete the original else delete the output

I have my storage VPS filled with videos, and hoping I can free up some space, their resolution is pretty big so I decided to re encode them with ffmpeg to a smaller resolution, I am doing every thing ...
0
votes
1answer
39 views

How to terminate cat command within a shell script

I wrote a shell script that uses cat and tr commands to generate a file. My shell script looks like #!/bin/bash printf "generating random file > plaintext \n" cat -v | tr "a-z" "b-y" < ...
1
vote
3answers
141 views

Bash long string, no word splitting?

I want to tidy up some script with long commands, so that for example: { somecheck || somecomand "reallyreallyreallyreallyreallyreallylongstring" } &> /dev/null & becomes something like: ...
1
vote
2answers
57 views

How do I make a BASH loop

I'm very new to bash and Linux and I was wondering how I could make a bash loop so that when it runs, it will ask you how many times to run, and it will run that many times. I did it in LUA but I ...
0
votes
0answers
48 views

Counting program fails in arithmetic test

having a little trouble with this rather basic script. This script works on Bash in my macbook pro, but not on my Linux Mint desktop, which also uses bash. I can't figure out what's wrong with it, ...
2
votes
3answers
254 views

How to find a specific 'string' and print out the whole line?

I have a file named myfile.csv containing the following: abc:123:myname:1231 def:423324:arbitrary:value:string StackExchange:Unix:Linux From the terminal I run ./myscript.sh def The contents of ...
1
vote
2answers
65 views

Using command substitution

The shell variable number contains 1 1 1 1 1 separated by tabs. I want it to contain only the first 1. I'm trying number= $(echo "$number"| cut -f 3 ) and I get the error "1: ...
2
votes
3answers
70 views

How do I remove the extra 'garbage' from this logfile?

I'm having some issues with log files from IIS 8.5 which I want to process with AWstats. Since my IIS servers are behind a load balancer I had to add a custom logging field, X-FORWARDED-FOR. However, ...
1
vote
1answer
133 views

Sed command that would ignore any commented match

I'm trying to create a sed command using regex in order to substitute something in a text file only if it is not commented but I'm running into some troubles due to my almost non-existent knowledge of ...
-1
votes
1answer
24 views

How to make a process wait in the background and be able to be killed by signal other than KILL

I want a script run in the background, take some actions for every hour. It should also quit if receiving a signal. And at last, it should perform some clean-up actions before quitting. Based on the ...
1
vote
2answers
42 views

Background processes mix up order of shell script execution

Can someone explain me why the script echo one && echo two & echo three && echo four gives me [1] 3692 three four one two [1]+ Done echo one && ...
0
votes
0answers
24 views

Is there a way to add a timestamp to the logs for qsub job?

I'm submitting jobs on a cluster via qsub but the error/output logs don't have a timestamp, making debugging more difficult. Is there a way to add timestamps to the logs in the bash script? Appreciate ...
0
votes
3answers
113 views

How do I copy the latest file from one directory to another?

I have 3 zip files in a directory. I want to copy the most recent version to a backup directory. My code works fine for .sh and other files, but not for .zip. Is there something else I have to do? ...
14
votes
9answers
524 views

Filter or pipe certain sections of a file

I have an input file with some sections the are demarcated with start and end tags, for example: line A line B @@inline-code-start line X line Y line Z @@inline-code-end line C line D I want to ...
2
votes
4answers
138 views

How to make diff command ignore certain lines of second file(bash)?

For example: file1.txt: I need to buy apples. I need to run the laundry. I need to wash the dog. I need to get the car detailed. file2.txt I need to buy apples. I need to run the laundry. I need ...
-1
votes
1answer
38 views

Cron job * is replaced by file name in current directory [duplicate]

This is my first shell script program, so i think this is more likely a silly question for you all. Overview of problem My need is to write a shell command for installing our Node.js server. ...
2
votes
3answers
279 views

KSH/BASH Maximum size of an Array

What is the maximum size of array for ksh and bash scripting ? Example: Suppose I have an array of 10 elements than what will be maximum number of string count that a particular index of an array can ...
0
votes
1answer
83 views

Bash detect ascii art [closed]

For bash script, is there a easy way to detect if a text contains ascii art? An example of ascii art:
-1
votes
1answer
45 views

Replace mutiple strings with different values in a file using unix [duplicate]

I have a file in which the data is like below, 01,0000000,xxxxxxx/ 02,xxxxxxxx,yyyyyy/ 03,test1,41203016,,/ 01,0000000,xxxxxxx/ ...
0
votes
2answers
40 views

recording total runtime in bash script

I have the following script. When it runs it prints the Start and end Times to the file 'result.txt'. However, I also want to record the total runtime (end-start), but where I am doing echo runtine ...
0
votes
3answers
208 views

Remove special characters in a text file

I have a text file which contains in each line a sql query. For each line, I need to remove some special characters. Expl: if I have: select * from Users; insert into Users values ...
0
votes
0answers
34 views

KSH/BASH Comparsion b/w Two Array and then logical OR operation at other function (GNU bash 4.2 version)

I am new to unix and learning it basics. I wanted to compare same index of two different arrays and on the basis of comparision I wanted to put a data to other array. First I tried to use it ...
0
votes
1answer
50 views

How to accumulate data for the previous x number of days

Q: For the argument of the question, say today is 26/03/15. How can I 'accumulate' data for the last 5 days. But these dates are just an example. Ideally I would like to be able to accumulate data ...
4
votes
5answers
358 views

Script tries to create files even though it shouldn't have to?

I have a folder which contains some folders, these folder are moved very often so I made a script to see if they exist, and if not then create them. This is what I did to (which I though would) ...
4
votes
1answer
180 views

Why does `du -sh *` complain about invalid options?

I've searched my best through Google, but for the life of me I can't figure out what to use instead of * (asterisk) after a recent update (even Wikipedia seems to think du -sh * and du -sh * should ...
4
votes
3answers
302 views

KSH - if/then/else vs. double amps (&&) and double pipes (||)

I am wondering what are the best practices regarding if/then/else ; I tend to use the following form (because I find it easier to read) #!/usr/bin/ksh # [[ -f /path/to/target/file ]] && { ...
1
vote
1answer
45 views

read input from user in while loop having input and output redirection

This is my code: while IFS=',' read a b c; do read input echo $input done 3<&0 < input.csv > output.txt I took care of input redirection by redirecting through pipeline. But ...
0
votes
2answers
85 views

How can I filter ping results by time?

How do I filter out any pings that are under a certain ms, ie, only echo ping responses above 500ms to the text file? IP=$1 SECONDS_Between_Pings=$2 ping -i $2 $1 | while read pong; do echo $(date) ...
1
vote
3answers
93 views

UNIX KSH/BASH Call by Reference using Array (at GNU bash 4.2)

I am new to Unix shell scripting My code is as follows: i=0 for var in 'a' 'b' 'c' 'd' 'e' do content[i]=var ((i=`expr i+1`)) done a=10 b=50 c=40 d=90 e=100 Now I wanted to print the local ...
1
vote
2answers
60 views

Redirecting stdout and stderr of specific lines

I am reading a file and redirecting the entire output to a file. I would like to redirect stdout and stderr of certain expressions to screen as shown below (just an example): #!/bin/bash OLDIFS=$IFS ...
3
votes
4answers
67 views

Traverse, copy & transform file names

My issue: I need to copy log files, all with identical names, but stored 1-deep in subdirectories, and change their names. I'm copying from the a folder called Logfiles which contains a bunch of ...
0
votes
0answers
43 views

shell calling another shell program fails when run by crontab

I have scheduled to run the run.sh program like this: 16 09 07 * * root /opt/db_maintain/run.sh > /opt/db_maintain/temp-log and here is the run.sh: #/bin/bash #********* Saman ********* ...
2
votes
1answer
97 views

About executing shell script

Suppose I have a shell script file foo.sh. I can do chmod + x foo.sh and change it into an executable file. In Kernighan-Pike: Unix Programming Environment (UP) they show that after this typing ...
-1
votes
1answer
57 views

Generate a tarball or (.tar.gz) of the recently modified files in the directory

As the title says, I need help creating a linux script that generates a tarball or (.tar.gz) of all the files in the directory passed in as an argument to the script and have been modified in the past ...
2
votes
3answers
127 views

Tool to generate TCP traffic

I want to generate a TCP traffic starting from the port 0 to the port 65535. 1 tcp packet for each port with 1ms between 2 packets. The generator should not care if there is a TCP ACK or not. Are ...
1
vote
1answer
66 views

KSH/bash for File Creation Dynamically

I am new to ksh and unix and I am learning it: I wanted the following:I have a directory name tmp on that directory on basis of FileName Category I wanted to create 'n' number of files dynamically. ...
2
votes
4answers
161 views

How do I extract the first integer from text string in a column of a tab-delimited file?

I work in Medical Genetics and often have delimited text files where in one column (ex. column 5) there is a text string with a "mutation" in our jargon: c.2458C>T or c.45_46delAA or ...
0
votes
2answers
101 views

Check whether text contains non-ASCII characters in a shell script

I have a file, I want to determine if it contains only English ASCII characters. I thought this is a very common question, but when I googled it, there is no direct answer or related. According to ...
0
votes
1answer
47 views

How to change bash script output when the script is running?

I have the following loop which counts from 0 till 99: #!/bin/bash for ((i=0;i<100;i++)); do echo $i sleep 1 done Is there a way to change the result of the output from terminal while ...
17
votes
2answers
2k views

How did this '&' at the end of my command, make the script SO fast?

While solving some CTF challenges online, I came across a situation where I needed to bruteforce a server. This is the code I wrote: #!/bin/bash for i in {0..9}{0..9}{0..9}{0..9} do echo ...
3
votes
1answer
52 views

automate the process of fixing all broken links

There are lots of broken links in my system. I wrote a script to relink all broken links. But, after the scripts runs, find would again show me that the links still exists. This is my code: find ...
2
votes
2answers
238 views

how to check if both parameters are set in bash? [closed]

Say I have a executable bash file script.sh. I want to use it as ./script.sh p1 p2 p1 and p2 are two necessary parameters for this command. If either one of them is missing, the command should ...
2
votes
1answer
79 views

Using find and sed to copy 20th line of many files into one file

I have a folder called "PKA1" Within this folder I have several folders that look as: 1eV, 2eV .... 30eV Within each of these I have subfolders I have a file called PKA.dump I want to copy the ...
0
votes
2answers
92 views

Recursively remove files with idx > 10,000

The problem In the current working directory I have several (very many) folders and some of them have lots (like 100,000+) of files inside. My goal is getting just the folder with 10,000+ files and ...
1
vote
2answers
131 views

Debian: umount /media/usb0: “Operation not permitted”

I recently moved from Ubuntu 14.10 to Debian Testing. Under Ubuntu I had a shell script for backing up my home folder to a USB stick. The last line of the script unmounts the USB stick. Adapting it to ...
4
votes
2answers
167 views

Increment a variable using a Bash script

I have a file that contains the following text. // // test_file.h // test project // // Created by Test User // #ifndef test_file_constants_h #define test_file_constants_h // Generic includes ...
2
votes
4answers
145 views

How can I find the program I'm hiding in bash

Say I have PATH="home/bob/bin:/usr/bin". I am writing a bash script /home/bob/bin/foo that will do some munging and then call /usr/bin/foo. Of course I want to be able to use this script on ...