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

learn more… | top users | synonyms (2)

2
votes
1answer
3 views

Find repository names from gitolite info output

How do I extract the names from the gitolite info command output, for further piping into a script? I'm writing a migration script to migrate all my repositories from gitolite to a Gitlab server. ...
0
votes
0answers
10 views

How to filter some files out of my directory?

I have some files in my directory. They can be classified into two categories: the files' name pattern in class one are like 1000-24-1-7-1 that have five numbers separated by four dash; the files' ...
2
votes
2answers
35 views

Create variables and assign values via loop (bash)

Is there a way to create bash variables and assign them values via a loop? Something along the lines of: #!/bin/bash c=0 for file in $( ls ); do var"$c"="$file"; let c=$c+1; done EDIT: ...
1
vote
2answers
29 views

Ping a host, check if alive or not, and send result to file via a shell script

To clean out my custom hosts file and remove dead domains on Windows I ping the hosts from domains.txt, and if I get a reply I add that host to result.txt: @echo off >result.txt ( for /f %%i ...
0
votes
0answers
17 views

Bash Scripts arguments and G++ static and dynamic library generation [duplicate]

I have a library named matrix.cpp that is used by a program named test.cpp. Now, I want to write a BASH script which takes matrix.h and matrix.cpp as input and generates matrix.a and matrix.so ...
4
votes
1answer
217 views

Write the same file multiple times to one file using dd

I am trying to create large dummy files on a drive using dd. I am currently doing this: #!/bin/bash writeFile(){ #$1 - destination directory/filename, $2 - source filepath $3 - blocksize, $4 - ...
1
vote
1answer
15 views

need a detailed guide to start scripts and applications in xfce4

I am looking for a detailed explanation about where is the right place to start scripts applications during the boot process. It seems there is either confusion or not need for the detail I am looking ...
2
votes
2answers
51 views

Need to obtain Awk output in specific sequence

Data in file: 1234567-5678907 3456789-1234563 3456789-1234567 . . . . n Now I want the output in the below format: 1234567-5678907,3456789-1234563,3456789-1234563....n I have used below command ...
1
vote
1answer
64 views

Bash script won't work on current directory

I'm using Kali linux which is based on Debian and wrote an script to copy some files from where the script is based to a specified directory. But when I execute my script (called CopyFiles.sh), cp ...
-1
votes
0answers
18 views

useradd -c “Text” username does not work when reading data from a file [on hold]

useradd -c "text" username works only from within a script when parameters are passed to the script on the command line, but when the parameters are read from a file, it doesn't work
1
vote
1answer
123 views

LFTP mirror includes - including other directories other than what I've included

My question: How can I make sure LFTP only includes files AND directories using --include or --include-glob, and not download a bunch of extra directories from the root of the remote that aren't in ...
3
votes
1answer
3k views

Why does the filename contain question marks when I run a script on my remote machine?

I have a tiny script that simply fetches the current date, runs a PHP script and redirect the output (and errors) to a filename containing the current date. DATE=$(date +"%Y%m%d") ...
2
votes
3answers
56 views

Command line options with argument in shell script

I have a script to get ldap user name, email and mobile number: #!/bin/bash echo -n "Enter Unix id > " read UNIXID ldapsearch -x "(cn=$UNIXID)" | awk '/givenName/||/mobile/||/mail/' Here is the ...
0
votes
1answer
36 views

insert value from reference file

I have a daily csv file with thousands of rows. I have been asked to concatenate two columns, then insert a new column when a value in a given column matches a table from another file. Empty values ...
2
votes
1answer
30 views

ksh/bash Formatting Files through sed by cat file|sed command

I am new to unix platform, (Alternate Approaches can be discussed) I am trying to change the colors of content of a file conditionally. My file is: A B C D Value Value Value Value Value ...
4
votes
2answers
183 views

Best and short way to run a program if another is not installed

I have this code: #!/bin/bash num=${1:-undefined} cmd=$(which {banner,echo} | head -n1) until [[ "$num" =~ ^[0-9]+$ ]]; do read -p "Type a number: " num done for ((num;num>=0;num--)); do ...
1
vote
1answer
48 views

Why does sed not remove my empty lines?

Why does not this sed command remove empty lines? sed -e 's/\r//g' -e '/^{$/d' -e '/^}$/d' -e ':begin;$!N;/^state-text: {[[:space:]]\n/s/\n//;tbegin;P;D' -e "s/'/''/g" -e '/^$/d' <<< $myvar ...
0
votes
1answer
66 views

How to get rid of “\r” a the end of the line comming from pipeline in bash

#!/bin/bash sourcenode=$1 destnode=$2 path1=/root/test ssh root@"${sourcenode}" -t "echo "${path1}" | xargs -IDIR find DIR " | while read line do ssh root@"${sourcenode}" -t "stat -c "%a" ...
3
votes
2answers
27 views

locally created alias not being used if called using backticks (`)

I have come across this issue while trying to build up a script to do grep on multiple files for 10 different word. The script I created, is (minified) #!bin/bash alias grep='grep -n' out=`grep word ...
0
votes
1answer
33 views

find all directories (except `encoded`) in the working dir then delete all of them

I am trying to test this scenario, I have these files /encoded encode <~~~ a bash script /dir1 /dir2 .../dir2-sub test.meta what I wish is, for find to search for all directories in our current ...
5
votes
4answers
221 views

Converting `for file in` to `find` so that my script can apply recursively

I've been working on my first bash script for some time now (I just started UNIX this week). I have this idea of running a bash script to check some conditions and using ffmpeg to convert all the ...
11
votes
5answers
540 views

Convert underscore to PascalCase, ie UpperCamelCase

If I have a string that looks like this: "this_is_the_string" Inside bash script, I would like to convert it to PascalCase, ie UpperCamelCase to look like this: "ThisIsTheString" I found that ...
1
vote
4answers
35 views

Anyway to pass a variable to bc, having a command to be executed?

I need to pass certain variable to bc to get the output in floating point, var1=$((<some operation>)) var2=$((<some operation>)) #Needs var1 var3=$((<some operation>)) ...
0
votes
1answer
46 views

How can I get a shell script to change directory for me? [duplicate]

here is a small test I ran, to try and move me back to root: #!/bin/bash pwd cd / pwd It returns the current working directory, and then the correct new one, but when the script finished executing, ...
0
votes
4answers
3k views

How to match a file name suffix

How to verify if the name of a .xml file name ended with .any-string? e.g. .previous or .backup or bck12 etc ... I need to print the XML file name except for XML files that end with ...
0
votes
0answers
21 views

Extract table name , user and timestamp from a hive ddl statement in unix [on hold]

I am generating list of ddl statements from a hive database in a file (say out.txt). From out.txt i need to extract some information by reading each and every DDL. For example: [gand@grid1 ~]$ cat ...
-2
votes
0answers
29 views

Unix KSH/Bash : Diff files for selected fields/columnwise only {GNU Bash 4.2 Environment}

I have two files: F1: abc|abc|abc|abc|abc| abc|abc|abc|abc|abc| abc|abc|abc|abc|abc| F2 abc|abc|abc|abc|abc| bcd|bcd|bcd|bcd|bcd| My questions are as follows: Suppose both files will have same ...
0
votes
1answer
49 views

killing a job running in the background

I have started running a long job by creating a script that executes several commands on 20 or so datasets sequentially. I began in the xterm window with $ script.scr then typed <ctrl-Z> ...
3
votes
3answers
103 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 ...
-3
votes
0answers
22 views

Write a script that will send the following information to the [on hold]

Write a script that will send the following information to the screen, in the following format: Month Sales ===== ==== January 200 February 300 March 200 April 200 May ...
3
votes
1answer
565 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
1
vote
2answers
72 views

One-Liner needed: Stop httpd if running already & Start httpd if not running

As part of a provisioning script for CentOS 7 I am in need to have a one-liner that performs the following. Unfortunately, I have no clue how to achieve that. If httpd is running then stop it If ...
0
votes
1answer
36 views

how to write a shell script to run multiple programs

I want to run two programs ssh -f mike@c15-0330-02 'cd /home && nohup Rscript L_1.R> L_1_sh.txt ' AND ssh -f mike@c15-0330-03 'cd /home && nohup Rscript L_2.R> L_2_sh.txt ' I ...
0
votes
2answers
25 views

IPtables errors

I am working on a project. I am trying to write iptables rules to control network traffic. I have written some rules. When I try to apply them to the boxes that I am working on I either get locked ...
1
vote
1answer
35 views

If statement in shell-script only half-working

I've been trying to write a script to rotate my monitor, I'll then assign it to a keyboard key. I've been fairly successful in making it rotate once, however when I run the script again, it doesn't ...
2
votes
2answers
82 views

Passing a bash command line arguments containing #

I am trying to pass pound sign as a command line argument then echoing the argument. When I pass for example 2 # 2 then I echo $1 $2 $3, I assume the terminal will output 2 # 2 but it outputs just 2. ...
2
votes
5answers
371 views

Problems when trying to execute sh file from another sh file

I have the following script: #!/bin/bash if test -f "/path/pycharm.sh"; then sh ./pycharm.sh; fi I am trying to run pycharm.sh from a bash file and I've looked carefully to give all the ...
3
votes
2answers
74 views

using the variable “file” obtained from `for “file” in` and pass to another script fails [on hold]

I am trying search for all .mkv files in my current folder, then using mediainfo I want to put the height from its meta data to a variable, but it seems it is failing. This snippet: ...
0
votes
1answer
21 views

Nnumber of HTML redirects from cURL

My little script extracts DOI's from a csv files in order to check whether they are right. The number should equal 3, and if it doesn't, I want to output an message. #!/bin/bash ...
0
votes
1answer
37 views

grep two searched words

I could search lines that contain two specific words using the following in multiple files: for f in $(ls *.txt); do echo ">"$f; more $f | grep word1 | grep word2 done Now, I want to write a ...
2
votes
1answer
230 views

Storing longer text output in memory in shell variables vs Writing to disk

I have the below call to db2 database command line tool inside a loop, which runs 100k iterations. (the output from db2 is 5 rows of 20 chars approx per each call, total of approx 100k calls. The ...
0
votes
2answers
31 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 ...
3
votes
4answers
3k views

Wait for multiple files to be finished downloading

I have the following script which checks if there is a file in a folder and if the file is stable (this is for large video file I am receiving). #!/bin/bash cdate1=$(date +%Y%m%d-%T) ...
1
vote
2answers
40 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?
1
vote
1answer
77 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
vote
3answers
90 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: ...
0
votes
0answers
15 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
27 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" < ...
14
votes
9answers
461 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 ...
1
vote
2answers
56 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 ...