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

learn more… | top users | synonyms (2)

1
vote
2answers
37 views

How to test if a file starting with a particular prefix is present in a directory in shell script

I need to test if a file starting with "ant" is present in the directory. If that is present, I need to delete that file. The command that I am using now is test -e $FILE_PATH/$FILE_NAME I have ...
0
votes
0answers
13 views

Where can I find shell script for parse JSON on busybox?

I have an IP camera with armv5tejl architecture. There I have busybox. I have to be able to parse JSON responses from curl. The problem is that I don't have programs like: jq, jshon, jsawk... It is ...
0
votes
1answer
799 views

how to export table data in to .csv file using shell script

I need to get the data from mysql server and export to .csv file .i need to export data to new .csv file daily automatically. query:select count(*) count,create_date from tabpush where status=1 and ...
2
votes
2answers
17 views

Resize image in a script using Imagemagick

I'd like to create a bash script to resize images up to 800px keeping proportion... My code doesn't work in bash, but it works using identify with a single image : #!/bin/bash for file in ./**/...
1
vote
1answer
23 views

Optimize find -exec {} with multiple conditions : specific files in a dir and specific subdirectories in this dir

My problem is related to music encoding on my NAS and optimisation of linux find command I have write a script that is totally functionnal but I am sure this not the best way. To summarize: 1/ It ...
1
vote
2answers
39 views

Use sed to pick out a potentially multi-line log entry

I've been trying to come up with a sed command to pick out a single log entry from our app server logs. The logs are in this format: LOG|2016-07-26_15:37:45:536|entry1|! LOG|2016-07-26_15:37:45:536|...
-3
votes
0answers
19 views

Print lines in one file matching patterns in another file [duplicate]

There are some phone numbers in one file I need to grep information from other file using that numbers among larger set of numbers and their information and result should be placed in separate file ...
4
votes
2answers
17k views

Shell Script - syntax error near unexpected token `else'

With the following shell script, why I am getting errors syntax error near unexpected token `else' Shell Script echo "please enter username" read user_name echo "please enter password" read -s ...
0
votes
1answer
3k views

IBM V7000 scripts for monitoring

Hello (I'm no hard core coder:), I try to develop a script to do some very basic monitoring on an IBM SVC. My goal is to get some information about the nodes and my quroum status and then send ...
2
votes
3answers
182 views

How to check if files are different before copying and overwriting?

I use a little script that copy (using cp) a list of config files to another device. I wonder how to quickly check whether the files were modified since last time before doing it and exhausting the ...
1
vote
1answer
2k views

rc.local not being executed when os boots up

I have a script that needs to be run when os boots up. I added it to /etc/rc.local. It was working fine for sometime but now rc.local does not load at boot time. When i checked the permissions on the ...
1
vote
4answers
40 views

Create an associative array from the output of two commands

I am trying to create user directories based on an imported passwd file, and am trying to load the data into an associative array: array[username]=directory . I can load the fields into a separate ...
1
vote
1answer
17 views

Find capacity details and oldest file in Busybox format

I am using Mobax and it has Busybox installed in it. I can successfully get the capacity, available, used and used percentage of the directory and its sub-directories in Linux by typing: clear &&...
2
votes
3answers
41 views

Extract files with specific file extension and keep directory structure?

I have a lot of .CR2 and .ARW files mixed together in a directory structured by date (2016 has the folder 06 and 07 within it with a folder for each day in them. So a file could be located in 2016/06/...
1
vote
0answers
68 views

sudo kill: Operation not permitted over SSH

Using heredoc to execute multi-line commands on a remote machine. Trying to get pid of a server to kill that server located in the remote machine #!/bin/bash HOST_IP="10.180.5.23" read -p "For HOST ...
0
votes
2answers
70 views

Split file by pattern

Is there an easy way to split, for example, apache vhost file with multiple vhost into 1 vhost per file? Or something else, allowing to operate only one by one vhost to get grep output . preferred ...
-6
votes
3answers
71 views

Bash script won't run

I'm trying to run a bash script named serverloadtest.sh to test a server is performing correctly. However, when I type serverloadtest.sh all I get is 'command not found'. I'm definitely typing the ...
0
votes
0answers
22 views

How do I use a file as a command line switch [on hold]

I have a shell script that emails a group of application owners using a command line switch. I would like to change that script to use an editable file as the command line switch. That file would ...
0
votes
3answers
96 views

Compare a file with a column of another file

I have a file File1 with data as aaa bbb And another file File2 with data as: 2,aaa,234 w,bbb,589 4,ccc,675 I need to compare the File1 data with column2 data of File2 and print the matching ...
2
votes
3answers
36 views

Specifying redirection options through a variable, in an exec command

I want to be able to specify the redirection command/options via a variable (that I might set based on certain conditions, etc.). But when I run this bash script for example : REDIRECT=">>test" ...
5
votes
3answers
257 views

How to check if a glob has an expansion? [duplicate]

Is there a good clean conventional way to do this? For example, if there are any ".gz" files in a certain directory, I want to unzip them. But if there aren't, I don't want to see any error. If I ...
1
vote
2answers
37 views

Script to remove files based on threshold value [duplicate]

I have some old file in my Linux server and I need to remove those files which are older than 5 days based on the threshold value. log_space_checker() { Use=$(df -kh /logs | awk 'END{gsub("%",...
3
votes
5answers
192 views

Comparing multiple options in a bash (string)

I'm trying to enable only certain options when using the read command, and to exit the script if a wrong possibility was entered. Tried many possibilities (array, variables, syntax change), but I'm ...
0
votes
1answer
1k views

CSH - How to check if input is NOT number

Please help, I can only see forums with this question for Bash, KSH, and others Need to apply it on csh. to check if the inputted $2 is not number nor the word "all" if ($#argv == 2 && ($2 !...
3
votes
4answers
64 views

Continuously updating a variable in the background

I'm trying to have a script continuously run a loop that updates a variable in the background, so that the variable is up to date each time it is used. After looking for near an hour, I've come up ...
1
vote
1answer
56 views

How to actively grep log for the last 15 seconds for a phrase?

I have this bash script and inside the script, I am trying to grep a log for the words "status change" and then after I find the most recent line that contains the words "status change" (aka the most ...
1
vote
1answer
31 views

wrapper script: fork: retry: No child processes

"myapplication" needs some setup or clean up done, so I use the following wrapper script: #!/bin/bash echo "Do important set up stuff" myapplication echo "Clean up" and put it in my path, named "...
0
votes
2answers
50 views

Define a set of values for a variable in shell script

I want to define a set of values for a single variable. E.g. singleDigit={0,1,2,3,4,5,6,7,8,9} If the user gives 10 it should exit with an error. How can this be achieved without using a loop, but ...
-1
votes
1answer
61 views

Script to delete all files and keep only latest file

Any advise on how to do delete all files and only keep the latest file in each sub-directories, starting from a specific directory? This is what I have tried: #!/bin/bash find /home/ftp/ -type f | ...
0
votes
1answer
26 views

Start Docker container and open web browser on host

I recently faced one non-trivial (for me) case. Maybe you know any way to solve it. I have a shell script that runs Docker command to start the Ubuntu container, which ends up with running guest Bash ...
0
votes
0answers
27 views

howto perform a concatenaned command and set result on variable

I need to build a command concatenating other smaller string values: function processES { local status=$KO_UNKNOWN local method="GET" if [ ! -z $1 ]; then method=$1; fi local curl="curl -s -...
4
votes
3answers
392 views

Recursively find all files named “file.txt” and execute a sed command

The challenge of my task is that the file.txt can be in subfolder or in sub-sub folders. The general structure looks like this: folder |___subfolder |_____file.txt | |...
0
votes
4answers
55 views

read phone numbers from file and store them in other file uniquely

I have input text file e.g myfile.txt which is contains data like WO_ID ------------------------------------------------------------------------ moveover_virus_8493020020_virus.final ...
2
votes
1answer
22 views

displaying a date after specific number days by reading a number

i have a file, in which there is a line Password=md@2507 where 2507 is the date when i changed the password for the last time. i want a script that read the date from the Password line of that file ...
4
votes
2answers
60 views

Best way to ensure that a script is run once a period?

I need a certain script to run once a month (others viewing this question may need it to be run once a day/week/year/5-day, etc). I know I can use cron to do so with: 0 0 1 * * ./script.sh But what ...
-1
votes
1answer
35 views

Script to monitor a new file

I want the script that to monitor the new file that which comes every day one time to the specific folder in windows Admin proxy and when the file comes we need a mail that should come to us ...
1
vote
1answer
29 views

Finding the length of a terminal session

I'm attempting to create my own bash script to output the length of the current terminal session, as well as do various other things with said length. The problem I'm running into, is that in the ...
3
votes
2answers
133 views

executing alias on variable in bash

I am a bash newbie and I came upon this strange behaviour in my bash script. #!/bin/bash V=a alias $V="echo test" echo $(a) #returns 'test' echo $($V) #returns ...'a: ...
1
vote
0answers
50 views

Task Automation With .EXE program and Bash Script?

There's a Windows program called Visipics. It finds similar images, not merely duplicates. I find it superior to findimagedupes (I use it with Manjaro and Linux Mint) and competing Windows programs, ...
7
votes
1answer
136 views

How to extract the string between two \n in a file

I have a file with pattern <span class="WebRupee">Rs.</span>\n29\n<br/><font style="font-size:smaller;font-weight:normal">\n3 days\n</font></td>, <td class=...
3
votes
2answers
56 views

Echo the list of process not running

I have developed a script, the script refers to a file to start the required processes on that server. The script times out after 180 secs. At the end of the script I would like to display the ...
0
votes
2answers
41 views

explain recursion syntax

I'm new to shell, and UNIX / GNU/Linux. I'm trying to understand this syntax that is part of a recursion function: [ $i -le 2 ] && echo $i || { f=$(( i - 1)); f=$(factorial $f); f=$(( f * i ...
0
votes
1answer
17 views

How to update Mint-Y theme and icons using a script

Situation: Mint-Y is a work in progress and it will continue to change and to improve, with your feedback, after the Linux Mint 18 release. Source: https://www.linuxmint.com/...
7
votes
5answers
7k views

Delete spaces, hyphens, and underscores in filenames?

What is a good command to delete spaces, hyphens, and underscores from all files in a directory, or selected files? I use the following command with Thunar Custom Actions to slugify filenames: for ...
3
votes
1answer
2k views

bash: non blocking read inside a loop

I have a following small bash script var=a while true : do echo $var sleep 0.5 read -n 1 -s var done It just prints the character entered by the user and waits for the next input. ...
0
votes
1answer
34 views

how do you make a list/file for pacman to install from

I am trying to move from one arch install a (partitioned one) to another (a less-partitioned one) on my computer and I want a similar set up. So I was wondering if there was a simple way to get pacman ...
11
votes
2answers
421 views

Is there a way for shell script to know which program has executed it?

In *nix world, is there a way for shell script to have information about which program has executed it? Example: /path/to/script1 /path/to/script_xyz in this imaginary scenario, script_xyz would ...
0
votes
2answers
32 views

Preform operation in bash only if a variable is less than a second variable

I am building an OS for a virtual machine I made, and while progress has been coming along swimmingly, I have been stuck for a good several hours on what should be a very simple issue: I am designing ...
0
votes
3answers
50 views

How can I delete a line from a file when the line contains a specific string? [duplicate]

I have a file which is comma separated. I have to find specific text and then delete complete line. e.g. 123,aaa,bbb,888,8881 124,bbb,ccc,999,8881 125,ccc,ddd,888,8883 I have to delete the line ...
-2
votes
1answer
75 views

quick and easy way to comment out multi lined print statements

Is there a quick and easy way to comment out multi lined print statements? something like this? printf("3387 strings_line_tokens[lower_bound_of_big_boy_counter] %s \n", ...