Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [shell-script]

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

2
votes
3answers
42 views

Read from a file and return new line with loop

I have a file like foo.txt xxx B=C D: A yyy F=H D:A zzz K=L D: A fff M=H D:/llll kkk S=D D: /kkkkk this is what I try to get; xxx B=C; D: A ;pass yyy F=H; D:...
0
votes
1answer
18 views

How can I run a bash script from an absolute path versus a relative path

I have a file in my root directory called bash_scripts and within it I have a file called create_py_dir.sh. At present the only command in the shell script is pwd, which I am using just to ensure it ...
0
votes
1answer
20 views

Simplify multiple mkdir and symlink in a loop bash

I'm performing the following operations # Mount cache directories mkdir -p $SHARED_VOL/track/$TRACK/.gradle rm -rf ~/.gradle ln -sf $SHARED_VOL/track/$TRACK/.gradle ~/ mkdir -p $SHARED_VOL/track/$...
0
votes
3answers
24 views

I/O error when passing command line argument to a shell script

I have written a one-liner bash script(bright.sh) to manually adjust the display brightness. sudo sh -c 'echo "$1" > /sys/class/backlight/intel_backlight/brightness' Here I take the brightness ...
-2
votes
0answers
28 views

What is the use of set -x command in shell script [duplicate]

I could see most of the shell script starts with set -x command. I’m not sure on the use. Is it for debug purpose?
1
vote
4answers
53 views

How to rename files pulled from a list of files using a single command or line

I have a project named my-project with the following file tree. my-project/ (before) . ├── src │ ├── index.html │ ├── main.js │ ├── normalize.js │ ├── routes │ │ ├── index.js │ │ └── ...
1
vote
0answers
12 views

ksh keybind trap

I am trying to follow this code sample http://www.kornshell.com/examples/keybind # Example from page 98 typeset -A Keytable trap 'eval "${Keytable[${.sh.edchar}]}"' KEYBD function keybind # key [...
1
vote
2answers
29 views

Bash-Script: How to insert Variables into Bash-Script?

The following bash script is working completely fine: #!/bin/bash echo '!PaSsWoRd!' | openconnect --csd-wrapper=/home/user/.cisco/csd-wrapper.sh --authenticate --user=abcde123 --authgroup="tunnel My ...
1
vote
2answers
34 views

Trying to perform two operations on a single huge source file to gain performance

I am performing two operations in a single Linux command. The operations are: Sending data from source file into a new target file. Counting the number of records in the source file. For example: ...
1
vote
2answers
302 views

cat output in the case of if else statement

os_version=$(cat /etc/issue |grep Ubuntu) if $os_version then echo found else echo notfound fi When I tried it on an Ubuntu machine it says ./test: line 2: Ubuntu: command not found notfound This ...
0
votes
1answer
35 views

Unix Function func_name ### {{{ purpose of #and {

Function func_name ### {{{1 { Function defined Return statement } ### }}}1 I’m not sure on the purpose of these curly brackets and ###
0
votes
2answers
29 views

how to write some text into a file in different machine

I have 2 machine machine1 and machine2. I want to write from write some contents into file in machine2 from machine1. In a same machine I can run sudo cat ~/.ssh/id_dsa.pub >> ~/.ssh/...
0
votes
1answer
40 views

Unzipping .tar.gz or .zip

I am writing a scriptwhere in a file there are .zip files and .tar.gz files. I have to extract the files. I know how to use tar for tar.gz and unzip for zip files but don't know how to take decision ...
0
votes
1answer
25 views

Shell/terminal/bash command or script for copying list of files from one project to another

Let's say I have a project called my-project/ that lives in it's own directory and has the following file structure. my-project/ . ├── src │ ├── index.html │ ├── main.js │ ├── normalize.js │ ...
0
votes
2answers
56 views

How to time a program in my script? [duplicate]

I'm writing this script where I have to run a program, time it and write that time into a text file, it must be in seconds with 6 decimal places. So far I have this: #!/bin/bash MAX_THREADS=8 #2 ...
0
votes
1answer
24 views

How does dmenu_run works?

My system is Debian 9.4 which uses linux kernel 4.9.0-8-amd64 and echo $SHELL on my system gives /bin/bash and /bin/sh is a link to /bin/dash. I was curious of why every time I run an application ...
2
votes
3answers
102 views

How to compare two files and if found equal ask the user to delete duplicate file by using shell script?

I am learning linux and was given this problem as my homework but i can't solve this that how we can compare two files content in shell mode. (Here, we can assume that both files having text content ...
0
votes
2answers
50 views

Provide password to bash script [on hold]

I have got a bash script, that encrypts different files. This script prompts me to enter a password for each file(to encrypt). Is there a way to give the information needed for the script as ...
-1
votes
2answers
33 views

Retrieve Field Rows from a Pipe Delimited File [on hold]

I need to get first 9 words from a pipe delimited file and then next 9 words. cat a.txt a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z| cat new.ksh #! /bin/ksh a=`awk -F "|" ' { print NF-1 } ...
-1
votes
0answers
27 views

Oracle login : Jenkins job fails using the script, but the same script works when triggered from a putty console [on hold]

I have a script which basically logs in the Oracle DB, and starts/stops the instance. When I run this script through a putty console, it works. Here's the output. SQL*Plus: Release 12.1.0.2.0 ...
1
vote
1answer
29 views

Using git interactive rebase from within a bash script

I'd like to create a bash script to automate a sequence of Git actions I do very frequently to apply my unstaged changes to an earlier commit, as in: Stash changes; Enter interactive rebase; Edit the ...
0
votes
1answer
30 views

How can I use awk to get value multiple times from one file to other file?

File1: 01 999 234 432 666 02 888 453 234 763 03 145 334 235 456 04 234 784 482 785 05 868 453 546 787 File2: 01 01 02 03 03 05 As I want to do matching between the first column of the 2 files and ...
0
votes
0answers
51 views

Tail with case statement is not working properly [duplicate]

I want to monitor the logs continuously and echo the output if keyword appears then continues the monitoring!! My question is how to perform the below operation tail the logs if keyword[down] ...
1
vote
0answers
53 views

tail -F is not working with while and case statement [closed]

I want to monitor the logs continously and echo the output if keyword appears then continues the monitoring!! My question is how to perform the below operation Tail the logs. If keyword[down] ...
1
vote
1answer
22 views

Excluding certain files from moving but move hidden ones too

In my deployment script I have such as code to exclude certain files. shopt -s extglob mv !(deploy.sh|file1|file2) ~/$public It works almost well but ignores hidden files so they are not moved. How ...
-1
votes
0answers
30 views

How I need to create retry shell script to retry the timedout ones? [closed]

I have few timeout project_Id's in the sql table and I need to write a shell script to retry those timed out project_id's.How can I do this mechanism as I am new to shell script and how I need to call ...
0
votes
2answers
30 views

“Globally Store” PID of file started from bash script

I'm compiling a latex file in a script and then I'm trying to either open a new pdf reader window or reload the current one (llpp being my reader), so after compiling my script does pdflatex $...
1
vote
2answers
39 views

Processing command parallel per batch

So, I have 10 CPU core and 20 data to process. I want to process the data in parallel but I am afraid if I just process 20 at once it will make some problem. So, I want to process 10 data 2 times. Is ...
1
vote
1answer
48 views

Transformation of output of CPU usage

How to convert output of this command ps aux | awk 'NR>1{tot[$3]++;} END{for(id in tot)printf "%s %s\n",id,tot[id]}' into pie chart. I have tried to make changes in the following pie script using ...
0
votes
0answers
21 views

Silent failure adding user to group

As part of an environment setup script we have the following snippet which installs docker: if [ ! "$(docker -v)" ]; then infoMessage "Setting up Docker..." echo "Updating system packages.." ...
2
votes
1answer
32 views

Automating postfix installation

I have been trying to automatically install postfix in a non-interactive way via startup-script on machine boot up. After a bit of research I found out some suggestion that I could try to install it ...
-9
votes
0answers
31 views

Writing a shell script [closed]

Need to read the list of URLs from a .txt file and create an output of the following requirement Name of the domain from the file IP the domain resolves to HTTP code that is received when we send a ...
0
votes
0answers
37 views

How to know if a script is already running [duplicate]

I want to know from within the script if that script already running. A regular look on ps won't cut it as it get's different arguments in different order.. So the function should do: ...
0
votes
2answers
78 views

How do I detect whether my terminal has focus in the GUI from a shell script?

Problem/Goal description Ideally, I would like a good way of detecting from a shell script whether or not the window has focus. By a "good" way, I mean some way which requires minimal steps and ...
3
votes
1answer
60 views

What is calling my executable *.sh script?

A long time ago I copied/modified a script that used inotify to tell me the results of an automatic clamscan when something was downloaded to Downloads - I followed this online resource: https://...
1
vote
1answer
18 views

bind variable and shell scripting with sqlplus [closed]

I wish to execute DMLs using bind variable with shell scripts. For example, something like: #!/bin/bash SH_NUM=10 sqlplus -S test_user/test_pass <<EOD var a number; a:=${SH_NUM} insert into ...
0
votes
1answer
15 views

Function to find all files in a directory and list their filename, without the path, size and type?

I current have something like find . -type f -execdir stat --format="Name: %n Size:%s bytes Type:%F" {} + this does parts of what i want however it displays the full file name including the path ...
-1
votes
0answers
18 views

Cannot execute java class from within a shell script [closed]

I am not able to run a java class from within a Unix shell script , however the same command when I am running stand alone, it runs successfully. I am using java -cp class_name arg1 arg2
0
votes
3answers
50 views

Script execution to continue even if redirection to a file fails [closed]

Its a typical scenario that, we redirect script outputs to a file. Either because of a permissions issue or whatsoever reason, output file cant be created. (Typically, these are log files ...
0
votes
1answer
43 views

awk: find common data between two files

File 1 (Master Data): 12345|abc 11223|xyz 23234|pqr File 2 (Sub set of File1): 12345_ASDD|PASD|AWOP 11223_PLDD|EVAAA ASDAS|ASDD 23234_MJKJLO|OKEI JSN|OPIE Output: 12345_ASDD|PASD|...
0
votes
1answer
49 views

a shell script to list files with date-1

I have some files like T24_STFBNK_CUSTOMER_2018100107553815383733380046446200.txt. The bold numbers 20181001 is the date of the file,I need a shell script to list the files which its date is yesterday ...
0
votes
1answer
26 views

How can I use grep in a loop and add new line of text each time to the same file?

I am trying to use grep in a loop and extract data from many files and then save them in a text file. Currently when I write grep sth > test.txt It writes it in the file test.txt, but when I run ...
1
vote
1answer
29 views

How to disable stopping a bash script from executing after calling some command?

I am trying to create a bash script to deploy an application. Prior to deploying, the application must be built using maven. The problem is, once the maven build finishes, the next command is never ...
0
votes
0answers
30 views

Script for Large CSV File to Convert IPv6 addresses to Number (or String) [migrated]

So I have a big csv file, over 1gb. There's a column with IP addresses in ipv4 and ipv6. I want to convert the ipv6 addresses into numbers, but there are too many rows for libre calc. So I'm ...
1
vote
1answer
23 views

unexpected token `<' when calling from parent file

I am writing a config generator script. When I paste the function code (setup_displays) directly in the terminal everything works. But when I call sh generator.sh I get this error: functions.sh: ...
4
votes
1answer
122 views

First argument passed to wrapper script is ignored

So I've got the following script: #!/bin/bash echo '-------------------------' echo $0 echo $1 echo $@ echo '-------------------------' exec su -- someuser -c "/tmp/elasticsearch-6.4.2/bin/...
0
votes
0answers
18 views

How to run a parameterized windows executable with wine inside shellscript

I want to execute a windoes program with wine inside a bash shellscript, the following ist not working: #!/bin/bash #initialize variables INPUT=$1 OUTPUT=$2 WORKDIR=$3 [...] if [ ! "$WORKDIR" ] then ...
1
vote
0answers
27 views

Run script when interface change it's status

I need static route when interface is up and delete this route when it goes down, but I have no interface config file to describe shell-command in it. I have IPSec tunnel created with LibreSwan and ...
-1
votes
1answer
47 views

cat command inside shell script closes the script shell and not execute

#!/bin/bash clean_fun() { sed 's/^#.*$//g' $pathfile > /tmp/arg echo -e "insert file name: \nfile path will be $HOME/Desktop/filename." read name sed '/^$/d' /tmp/arg > ...
1
vote
1answer
37 views

Running an executable without sudo

I have a small function in my .zshrc. It creates a command to search for and run an executable file, that may or may not exist, in the current directory, or a parent directory somewhere up the current ...