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
1
vote
0answers
17 views

date validation for a custom format in shell

i am writing a generic script for the custom format date validation . here is the script dateformat=$1 d=$2 date "+$dateformat" -d "$d" > /dev/null 2>&1 if [ $? != 0 ] ...
0
votes
1answer
16 views

/dev/sda **sometimes** confused with /dev/sdb by smartctl

I have a script - run from cron.daily that gathers SMART stats from two identical SATA SSD's. However, smartctl -A /dev/sda sometimes returns the stats for /dev/sdb - and if does so smartctl -A /dev/...
0
votes
1answer
23 views

send text file (column data with space) in a table format in mail body

Can anyone help me to send below data in html table format in mail body using shell script. sample file abcd "this is to test" 123 csdf "another test" 10000 I have created below ...
0
votes
0answers
22 views

How to ignore/prevent schedule by “at” command if it is already schedule for the same time?

Shell script file: schedule.sh #!/bin/sh echo $(echo ./task.sh $* | at $*) The above schedule.sh file execute dynamically by user using command: $ ./schedule.sh "2:34pm 2021-05-12" My ...
0
votes
2answers
25 views

For loop drawing from multiple files

I am quite new to Unix and would like to convert a script I previously had in R. For this I have three different files (of equal lengths) with different variants of file names. I would like to iterate ...
0
votes
0answers
22 views

.desktop file KDE Service menu - how to copy many files

I have a servicemenuitem for KDE which copies the selected file to the desktop. It works when one file is selected on the desktop, but when multiple files are selected, they are not copied. The -exec ...
1
vote
1answer
30 views

exclude a string when a range of numbers is successfully found. Followup to a previous questions about searching strings in a txt of house addresses

Context This is a follow-up question to a question I asked previously. A new detail/issue arose that I wasn't aware of prior to getting some amazing help from Kamil Maciorowski and Cyrus. I chose ...
-1
votes
1answer
40 views

Problem output result after summing values in BASH

I need to use while loop with If statements to store only 1s and 0s, then check which one is more popular than other. I am encountering a problem when I try to execute the script: Input: bash vote.sh ...
0
votes
2answers
70 views

Is escaping shell aliases in scripts useful when executing scripts?

Does escaping bash aliases make any sense in any - not sourced and normally run - shell scripts? Consider the simplest situation with ls for which many users have re-defined its functioning with an ...
1
vote
1answer
41 views

Remove quotes from stdout. Pass string as file path

I was trying to create a bookmark file for my configs, and search for them using fzf. I tried both these methods but with no avail. editconf() { nvim $(cat /home/anupam/scripts/conflist | fzf) } ...
2
votes
2answers
86 views

Extracting texts between two markers not always working

So, a while ago I saw this snippet for extracting text between two "markers": # Usage: extract file "opening marker" "closing marker" while IFS=$'\n' read -r line; do ...
0
votes
0answers
21 views

I need advice on ways to improve my kernel updater script

#!/bin/bash KERNEL_VERSION=$(echo /var/db/pkg/sys-kernel/gentoo-sources* | tr -d -c {0-9.}) cp /usr/src/linux/.config /usr/src/.config-"`date +"%d-%m-%Y"`" cp -avL /usr/src/linux ...
0
votes
0answers
26 views

Bash script for sqlite commands

I wish to run a bash script that asks for a variable to be then used in a sqlite query. I have no real experience in scripting, anyway I've tried something like the following but it doesn't work. ...
0
votes
1answer
38 views

Visudo permission in file execute script

I'm trying to run a shell script via php but I'm getting a permission error, however I'm trying to add permission to my www-data user to use the sudo command without a password, but it's not working, ...
1
vote
2answers
57 views

shell scripts to pattern(s) search and list file(s) in a directory

I used ls | agrep "<search pattern #1>;<search pattern #2>;...;<search pattern #n>" to quickly and/or effectively perform a search/list of some file(s) in a directory with ...
1
vote
1answer
14 views

How do I remove a line containing text and then everything after that up until another token?

I'm using bash shell. I have a YAML file from which I want to remove certain blocks of text. /image-content: post: operationId: createEventPublic summary: Process events ...
0
votes
1answer
40 views

What does “[ ”$foo_user“ = 'foo' ] && foo_user='bar' || true” do?

I found this line in one of our repositories without any comments explaining what it does. I am fixing a bug that I found in this repository and don't know what to make of this line. I am unsure of ...
-2
votes
0answers
26 views

Super Script Shell [closed]

soy nuevo el Linux y estoy aprendiendo a base de tutoriales y con esta página. Quiero automatizar ciertos procesos muy repetidos y con Bash creo que encontré una solución, Pero ahora me encuentro ...
-1
votes
2answers
42 views

comparison to get only lines with changed values on a column

Given the following two csv files, previously sorted: file1 a,1,val1 b,2,val2 c,3,val3 d,4,val4 e,5,val5 f,6,val6 g,7,val7 file2 a,1,val1 b,2,val2 c,3,val3x e,5,val5x g,7,val7 h,8,val8 How can I ...
0
votes
1answer
29 views

Displaying number of columns and items in columns using a for loop

I'm writing a BASH script that asks a user for the number of columns and the number of items to put in the columns. The script will then put the numbers in the columns using for loops. # Number of ...
-2
votes
1answer
38 views

How I can read multiple files [duplicate]

FILE1: at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:940) at com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(...
0
votes
0answers
23 views

SSH into multiple machines and run multiple commands

Writing a script to ssh into multiple machines and running multiple commands. However once the ssh is successful I get the following from each host without a single commands executing, the for loop ...
0
votes
3answers
93 views

Can the words in these bash strings efficiently be inserted into an sqlite table?

I have two bash variables $FNAMES and $LNAMES that I want to insert into a table in sqlite and I'm not quite sure how to do it. Here's a mwe: #!/usr/bin/env sh FNAMES="John Paul George Ringo&...
0
votes
1answer
18 views

Is it possible to make keybindings for mpv to run shell scripts?

I'd like to change my webcam's exposure-time & gain... using something like v4l2-ctl -d /dev/video2 -c gain=15. As far I searched, the keybindings for mpv is located/configured at ~/.config/mpv/...
1
vote
1answer
35 views

How to check if command had any output (zsh)

I want to print a new line after a command if it had any output (I hope that this will make it more readable once my terminal starts scrolling). I found this: precmd() { precmd() { print &...
1
vote
2answers
27 views

Bash script working in root but not in crontab

I'm trying to execute a bash script on Linux startup, but it doesn't work. I have tried all of these commands in the crontab: @reboot bash /home/user/mysqlamazon.sh @reboot sh /home/user/mysqlamazon....
0
votes
1answer
33 views

How to Add and subtract date in existing file?

I am having file with date format YYYYMM. I need to do two operation addition and subtraction. for Addition in existing input file i need to do add(+14).( For example if i am having date 201610 means ...
2
votes
2answers
50 views

Add every nth line together

**edited for clarity as per recommendation I'm looking at averaging a number of data points given from multiple runs of a command. (in this case using the sysbench tool suite) Example input (this ...
0
votes
5answers
91 views

How to extract fields for specific line numbers that are passed as parameters to a bash script?

I have a file named data.txt with the following content: 1 aFDLKSFD_FDSJFskadfsff_fsadklfj_fdsaf IT524234 2 bFDLKSFD_FDSJFskadfsff_fsadklfj_fdsaf IT524234 3 ...
0
votes
0answers
13 views

Attempting to run LDAP search in Script. DNS SRV: out of memory?

Good morning! New here on the forum, been a long-time user of the site. I am much more familiar with powershell than bash scripting and am attempting some automation. I am trying to write a script ...
0
votes
1answer
26 views

Read file accessible only from script in Unix

I have written a Base shell script that needs password/key which is retrieved from a file. Base Script---Calls---Key/Password File ---Base Script does further authenticates using the key retrieved ...
0
votes
1answer
17 views

i wrote the script scp/sftp with password, passphrase and private key , it work with winscp but not from my linux shell

#!/usr/bin/expect -f spawn /usr/bin/scp -i "/pkg/scripts/myppk.ppk" -P 11111 lulumea@11.11.11.11:/OUT/mycsc.csv /manpkg expect { expect "*phrase*" { send "...
-1
votes
0answers
44 views

How do I access a particular record in the END block of AWK/ [closed]

I am trying to access a particular record, and a particular field in that record. But I am in the END block of my code, so the FNR is fixed to my last line. Is there a word around?
-1
votes
0answers
30 views

how to create a random output from users input [duplicate]

I want to generate some random set of characters from the user input like from $firstname and $lastname in my script what can I use to generate it ???
0
votes
1answer
35 views

Grep returns “No such file or directory” in bash script , works manually

I am getting "grep: Filename: No such file or directory" while running bash .sh script. Command are running manually. File type is "ASCII text, with very long lines". Is this ...
-1
votes
1answer
35 views

syntax error when using the END special pattern in AWK

I am a beginner to shell scripting and I am trying to print out the maximum value of an array from a file that I am reading. The code works fine when I don't use the END statement but gives out an ...
0
votes
1answer
26 views

Creating symbolic links in a for loop

With a single argument, ln -s will create a symlink in the current directory: $ ls /opt/my_tests hello_world.c hello_world $ $ echo $PWD /home/chris/my_links $ ln -s /opt/my_tests/hello_world.c $ ls -...
0
votes
0answers
55 views

Bash script to create directory, move files and make them executable

I am brand new to Linux (Kali) and coding in general. In an assessment I have due I need to write a bash script in Terminal. The requirements for the script are as follows: Create a directory named ‘...
0
votes
0answers
17 views

running load on volume

Hi everyone here my query i need to run load on a number of volumes of a storage box but those volumes are not presented to the hosts as there are limited host available is there any script or ...
0
votes
1answer
41 views

Elapsed time counting

I have a small script (basically very easy this is the first I wrote) and likes to know the elapsed time, how long it takes when it is finished. Is it possible to count the difference between the two ...
0
votes
3answers
66 views

Bash script to move files in directories listed in a textfile

I have a directory structure like this. . ├── Round_1_Div2 │   ├── file1.txt │   └── file2.txt ├── Round1Div2 │   ├── file3.txt │   └── file4.txt ├── Round_2_Div2 │   ├── file1.txt │   └── file2.txt └─...
0
votes
0answers
38 views

problems with creating bash script with sed script

So, when i am creating file in my Docker manifesto with echo: RUN \ echo "#!/bin/bash\n\ mounted_tz=$(cat /etc/timezone)\n\ sed -i -r \"s~^(log_timezone\s*=\s*).*$~\1\'\$mounted_tz\'~\" ...
0
votes
0answers
23 views

bspwm - shell script for switching displays after dock / undock laptop

I'm using bspwm and I would like to write shell script that sets up layout of two external displays and moves all desktops from laptop monitor to them or vice versa, moves all desktops from external ...
0
votes
2answers
41 views

How does my linux OS make so quickly sign in process?

I have written this shell script to test sha-516 hash password string : myhash='$6$nxIRLUXhRQlj$t29nGt1moX3KcuFZmRwUjdiS9pcLWpqKhAY0Y0bp2pqs3fPrnVAXKKbLfyZcvkkcwcbr2Abc8sBZBXI9UaguU.' #Which is ...
-4
votes
1answer
37 views

What am I missing? I am getting some array error

I am trying to convert a c program to shell. But I am getting errors. Here is the program: $bt[] $pri[] $pp[] $temp echo "Enter the number of processes: " read n for((i=1;i<=n;i++)); do ...
-1
votes
1answer
68 views

How do I grep a exact string from multiple files at the same time

I have multiple files(text file) in a folder like below where the 1st file contains some paths as a string and the other with path+file_name. File1: [root@centos7 test]# pwd /root/test [root@centos7 ...
0
votes
0answers
35 views

Shell Script Loop Doesn't Stop

I am new to shell scripting (very very basic knowledge). I have been working on a simple script and I needed to control the user input through this script that I've written: #!/bin/bash read -p "...
-1
votes
3answers
43 views

How to get absolute path of found file using 'find' command in Linux?

I'm checking if file present with find command like following - find ${pwd} | grep 'Test.*zip' This command returns output with relative path like - ./ReleaseKit/Installable/Test-5.2.0.11.zip Is ...
-1
votes
2answers
55 views

Compare two csv files containing floating-point data and print their difference statistics

I have two csv files: a.csv and b.csv. Both these files contain same set of rows. For example: a.csv: Yield 5.68 1.34 1.47 9.01 7.59 b.csv: Yield 5.68 2.01 0.78 7.98 8.17 I need to compare these two ...
0
votes
1answer
70 views

How to use find with globs in a Bash shell script?

I'm trying to use find with globs in a Bash shell script. I've tried to both sourcing it and running it, but the command fails every time. #!/usr/bin/env bash # glob-test.sh - a script to test globs ...

1
2 3 4 5
283