We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [shell-script]

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

Filter by
Sorted by
Tagged with
0
votes
2answers
234 views

Its possible use special characters in a shell function name?

I have to create the function in shell script, that function name must contain the special characters. like >() { echo $1 $2 } Here my function name is >, If its ...
0
votes
2answers
989 views

Can I have a (bash) shell with expect running in the background?

I am trying to write an expect script that once started will watch my terminal and run a command every time that it finds a match. Is this even possible with expect? If so, would expect_background ...
0
votes
1answer
28 views

Different result for positional parameters expansion and custom array expansion

There is a difference in the output of commands that I don't understand, as stated below: INPUT="$@" echo "$INPUT ${#INPUT} ${#INPUT[@]} ${#@}" # outputs: a b c 5 1 3 arr=(a b c) echo "$arr ${#arr} $...
0
votes
1answer
56 views

stderr is being sent down pipeline but I don't want that

I have this: echo "$some_command" | bash 2> >(prepend 'r2g-stderr:' 'red') | prepend 'r2g-stdout:' 'yellow'; What I am trying to do: r2g-stderr: this is some stderr r2g-stderr: this is ...
0
votes
2answers
945 views

Adding array entries to existing JSON document from plain text input

I have a situation where i have output of one command, like this, 192.168.1.84 192.168.1.85 i want to use this, and make changes in another file, i.e add this ip addresses one after another like in ...
0
votes
1answer
1k views

command /opt/bin/date --date '-15 minutes 2016-04-27T14:14:47' producing result many hours before stated time

I'm using the following command in an attempt to work out the time 15 minutes before the timestamp: /opt/bin/date --date "-15 minutes 2016-04-28T16:58:55" '+%Y-%m-%dT%H:%I:%S' The problem is the ...
0
votes
2answers
1k views

bash scripting tput getting errors [closed]

I need to figure out what is wrong with this tput menu. #!/bin/bash tput setb 3 tput clear function main_menu { option=0 until [ "$option" = "4" ]; do echo " 1.) Monitor existing processes " echo ...
0
votes
2answers
133 views

Nested for Loop In Directory

I have two sets of files organized as such: #first directory /direc1/files file0.1.tar.gz file0.2.tar.gz file0.3.tar.gz file0.4.tar.gz . . . file0.22.tar.gz In this directory, I ...
0
votes
3answers
3k views

Passing Variable from one script to another

How can I pass a variable between scripts? Example: I have two test scripts: -- test2.sh #!/bin/bash echo "this is test2.sh" echo "varname is $varname" echo end -- tes1.sh #!/bin/bash varname="...
0
votes
1answer
3k views

Shell script to process service restart procedure

We're running a 3rd party TTY service on our servers, to support some thin clients manufactured by the 3rd party. From time to time, connection to a thin client can get locked up. Procedure is to ...
0
votes
2answers
1k views

Bash script error trying to find directory of script itself: unexpected end of file

Borrowing graciously from this StackOverflow answer, I want to find the directory a script is running in so I can load relative paths for it on login: The script is pretty small right now: SOURCE="${...
0
votes
1answer
492 views

xdg-open opens a specified htm file but ignores the tag (#) location within the page

I have a function in a bash script (openWebPage) which I want to open a web page and navigate to an id tag within the page. The url components are held in variables PIXPAGE="/home/bu5hman/pix/...
0
votes
1answer
2k views

parse first column of command output, get corresponding second column value

I am executing a command that outputs a table, as such: firstValue: a secondValue: b.y7 thirdValue: c-x-g 10:42 GMT Say I need the secondValue. I can't do this by row number, because sometimes ...
0
votes
3answers
3k views

Count files in a directory tree [duplicate]

For the consistency check of a backup program, I want to define a function which counts all files in a directory including all files in subdirs, subsubdirs and so on. The solution I am trying so far ...
0
votes
4answers
49 views

How can I do subdirectory manipulation in shell?

For example, running a command on n-number of sorted subdirectories, where n is an input. Or how can I run a for loop on a range of subdirectories where I can give that range as an input? Like the ...
0
votes
2answers
346 views

file command + how to view all results from file command

I use the file command in order to verify if file (PATH) is text/ascii file or encrypted file Because file command have allot of results ( small example in example 1 ) I want to get the all ...
0
votes
1answer
35 views

Pattern matching in a file and how to comapare that with another String

I am having a variable like a='Hope'. And I am having a file containing sentences like Time delay go straight Hope In this file I need to find "Hope" only. And I need to compare that with the ...
0
votes
1answer
145 views

Bash add text on line script [closed]

Trying to get my script to work but it won't work. Here is my script #!/bin/bash a="* * * * * /home/server/scripts/check.sh" b="0 06,18 * * * /home/server/scripts/checks2.sh" sudo sed -i '28s/^/'$b'\...
0
votes
1answer
42k views

How do I use: cat << EOF [duplicate]

I am little confused and not sure, how to add the cat << EOF style to my script. Would really appreciate a little feedback and help. Here is my script !/bin/sh #This is a disk mailer script ...
0
votes
1answer
414 views

Assigning stdout value to a variable

So I'm trying to make a sh script where I put a value that I get from a command, into a variable, in this case n, but I have no idea what I'm doing, and this here obviously doesn't work lol: 1 n=0 ...
0
votes
1answer
28 views

Reference the stdin sent from piped sender process

Say I have this: delete_lock () { if grep -q 'PATTERN'; then # some command here fi cat >/dev/null } node foo.js | delete_lock say the node.js process writes "foodog" to ...
0
votes
1answer
735 views

How to troubleshoot failing cron job

I have a crontab root file that looks like this: lab-1:/var/www/cdd# crontab -l # do daily/weekly/monthly maintenance # min hour day month weekday command * * * * *...
0
votes
2answers
50 views

Keep only 3 lasted date files(i.e. Appended date in the files) in the set of files and delete remaining files in the particular directory

I have one scenario which I should need to implement in the Unix. In a directory, I would like to delete the files based on the appended date at the end of the file, these files are XML back files. ...
0
votes
1answer
2k views

command not found using sudo in script

I am trying to execute sudo command inside a bash script. #!/bin/bash sudo node app.js and it throws me : sudo: node: command not found If I try to execute only node app.js (without sudo ),it ...
0
votes
1answer
841 views

Mandatory argument for script to run java program

My script is called: report_startDate It has the following line: $JRE_ROOT/bin/java -cp /home/me/report/config/:/home/me/report/jar/reporting-1.0-SNAPSHOT.jar com.me.project.report.Main $1 $1 ...
0
votes
1answer
8k views

Unix--Send attachment, subject and body of the mail using mailx

Can you please tell me how to send the attachment, subject and body of the mail using mailx command. I am using uuencode travel$datestamp.XLS Travel$datestamp.XLS | mail -s "International Savers ...
0
votes
2answers
2k views

map array of arguments and then convert to string

Say I have these bash functions in a script: foo(){ my_args_array=("$@") export my_args="${my_args_array[@]}" bar $my_args } bar(){ echo "number of args: $#"; } foo a b 'c d e' if I run ...
0
votes
2answers
288 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 ...
0
votes
2answers
155 views

Execute command when user interaction is detected ( ex: moving mouse, pressing key )

I am trying to make a bash script to turn down the brightness to lowest when idle for a certain amount of time but reverts back to its previous brightness when it detects user interaction whether it ...
0
votes
2answers
815 views

GETOPTS parse empty and nonempty args

I am trying to make script that has two switches -h and -d, -d having a mandatory number argument. After it there will be undetermined number of paths to file. So far, I have this, but the code seems ...
0
votes
2answers
573 views

How do I grep to find a file only matching a string enclosed with wildcards

I have to find a file with only a given number and a string. Ito find 856 enclosed with wildcards *856*. e.g. I have this fileA.txt with thousands of numbers: 45423542354235423542 ...
0
votes
0answers
243 views

Killing a process running executed with sudo without using sudo in kill command

So I have a server, and I have access to sudo to do one thing only: run a single whitelisted script (I'll call it the target script). I do not have access to sudo anything else. Problem is, this ...
0
votes
0answers
48 views

Passing directory from command line to shell script [duplicate]

I want to pass directory as a command line argument to the shell script. #!/bin/bash sourcedir=/home/dir/data cd $sourcedir find "$PWD" -maxdepth 2 -name \*_R1*.fastq.gz > list1 fastq_list=$...
0
votes
2answers
102 views

executing commands in shell and turnoff the default displays of commands in console [duplicate]

This is my script cd /opt/product/vinoth -- some operations -- cd - While executing this command cd - the old path get displayed in the console. is there is any way to block this from displaying in ...
0
votes
1answer
55 views

Add a line if it's missing

I have a data gathering device which records per second. Sometimes, randomly it drops a second or more. For example 166,1.09424,240,76,132 168,1.10088,215,76,132 169,1.10765,213,78,131 170,1.11458,...
0
votes
3answers
49 views

Add data to a particular line in a file

I need to build a script that adds comma separated values into a particular line in a file. Say I have a file with contents: DL1 : abc@kk.com,cde@kk.com,xyz@kk.com DL2 : hjk@kk.com,nbv@kk.com,tuy@kk....
0
votes
1answer
32 views

Add lines if they are missing from a data series

I have a data gathering device which records 5 attributes of data per second. The first column of the data is the time elapsed, in seconds, and is always sequential ie n+1. Data fields are comma ...
0
votes
2answers
57 views

Group files into average size of the largest file

I have 6 files and would like to group them by 2 or 3 according to the average size. file1.log 50G file2.log 40G file3.log 20G file4.log 10G file5.log 30G file6.log 70G File6 is 70G is the biggest ...
-1
votes
1answer
64 views

How to record numbers of array elements based on selection comparision criteria

I have many files which has many 2x2 arrays. In the present example I show only one file (file1) Input file(file1): 1: 6.1703 541.631 46.0391 2: 6.1930 537.446 45.9239 3: 6.1931 177.171 288.579 ...
-1
votes
1answer
578 views

Shell script does not run java, wrong parameters

I wrote a program in Java, which uses the RXTX serial port, so I had to include an additional library. At first I ran it from SSH, and it was working properly. After that, I was running some test ...
-1
votes
1answer
62 views

Cant use while loop because it is taking time is there any way faster way to get the final file..in linux [duplicate]

cat file_1.txt 100 200 name 100 200 100 200 150 300 150 300 150 250 150 250 150 300 name final file should be 150 300 150 300 150 250 150 250 i am using this command cat file_1.txt | ...
-1
votes
1answer
459 views

Combining Certbot with an Nginx server block maker

I have an Ubuntu 16.04 environment with a pure Nginx server and I use the following Bash script to automate creation of server blocks and corresponding (self-signed) SSL certifications. It allows me ...
-1
votes
1answer
498 views

How to write the bash script dynamic to print row and columns data and update the same data in the same file? [closed]

abc_hosts,pwd_host_id,pwd_host_id,hostname,ddd_status,dddd_status, start_hosts,,,,,,,,,,,,,,,,,,, ,1,o1,fhffhfh,1,1,fff,fdfd,172.33.33.33,172.30.30.12,172.30.30.11,oreere.dff,43,443343,1111,43435,...
-1
votes
1answer
77 views

Correct way to call a Bash function from all sessions

I use Ubuntu with Bash and I have a file hosting a script with 5 functions. Sometimes I want to call some function of these functions (but not all of them), directly from the CLI. I could say it's ...
-1
votes
4answers
1k views

SQL operation on csv file using bash or shell

This is my input file 0164318,001449,001452,001922 0164318,001456,001457,001922 0842179,002115,002118,001485 0846354,001512,001513,001590 0841422,001221,001224,001860 0841422,001227,...
-1
votes
3answers
263 views

Redirect nohup-heredoc stdout to stdin, to execute directly?

I aim to paste this heredoc script and execute so to install and timeout-uninstall PHPmyadmin after 2 hours, from security reasons. nohup bash -s -- $$ <<'EOF0' & #!/bin/bash -x apt-get ...
-1
votes
2answers
93 views

First match if we are on the first line of input, if so print the whole line, else print the first word followed by a comma

for eg: CREATE TABLE MWWDATA.ACK997 ( AKTYPE CHAR(2) DEFAULT '' NOT NULL , AKNUM CHAR(9) DEFAULT '' NOT NULL ); CREATE TABLE MWWDATA.APREIDEXC ( EMPLID NUMBER(15, 0) DEFAULT NULL ); I ...
-1
votes
1answer
268 views

How to sort and join files in linux with huge data and print blank values for the values which are not found

Consider the below files : file1: 1 2 3 4 file2: 2 3 6 9 expected output: 1 NULL 2 2 3 3 4 NULL NULL 6 NULL 9 I have tried paste file1 file2 | sed 's/\t/\0\t/g' | column -s $'\t' -t ...
-1
votes
2answers
66 views

Copying files while maintaining file attributes

Say, if I want to copy /etc/bin to a folder while maintaining the file attributes as well as parent directories. [The target folder should not just contain bin folder but /etc/bin.] Is the possible ...
-1
votes
1answer
568 views

I'm trying to prevent the execution of a command in BASH.. Doesn't work always [closed]

This is based on another question of mine I am trying to prevent executions of certain commands using a script. I got the script to work perfectly in interactive shells but for non interactive shells ...