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
1answer
18 views

Shell script, a function to verifie if FILES=$(ls) contains a file

I am a beginner in shell scripting and I need to find a function, to check if a variable exist in a list in bash. The list is generate this way: FILES=$(ls) and so I need to check if a file is there. ...
0
votes
0answers
2 views

Checking Background Jobs after Using Script to Submit

When I submit a job to the background using the below line, I have no issues using the jobs command to see the status. nohup orca result0000.inp > result0000.out & However, when I use a bash ...
0
votes
1answer
25 views

Bash - make counter print superscript numbers

If I had a script with a counter, printing numbers like this: #!/bin/bash while true; do i=$((i+1)) echo "$i" sleep 1 done; prints: 1 2 3 4 5 [...] how can I make the script print ...
0
votes
1answer
30 views

Absolute value of number

I have a single line of numbers separated by a space. read var sum=0 for x in $var; do ... #add numbers together $((sum += x)) done I need the printed value to be an absolute number I got ...
1
vote
2answers
38 views

is there a way to write a command with lots of options in a more legible\maintainable script format?

My question may not be clear enough, so here's a specific example. I have an rsync bin\bash script with a ton of option switches. Instead of: rsync --recursive --times --update --chown=root,root --...
0
votes
1answer
22 views

Validating header and trailer

I am new to UNIX and I need some help regarding validation of head and tail. I have a text file named data.txt where I have the following data: H,20200701 SK MK 3 Here the header has date and the ...
1
vote
1answer
32 views

Is it better practice to explicitly specify the full paths to commands in a shell script?

I'm having a discussion with a colleague: Is it better practice, or even needed, to explicitly specify the full paths to commands in a shell script (such as an install script, cronjob, etc)? For ...
-1
votes
0answers
32 views

How to set a valuable as an integer [duplicate]

I have a txt file and there has random numbers in it. I try to pick the smallest value from that txt file and set as an integer. I achieved "pick" part but I cannot set this value as an ...
0
votes
2answers
37 views

How to change wallpaper on xfce from terminal?

Linux kali-linux 5.6.0-kali2-amd64 #1 SMP Debian 5.6.14-2kali1 (2020-06-10) x86_64 GNU/Linux I want to change my wallpaper from the terminal. I tried methods suggested here and: Gsettings doesn't ...
0
votes
2answers
34 views

How to sync/backup files whenever change is detected?

I have two partition, one for use and one for backup. So, is there any tool for syncing the folder from first partition to second. Also, the tool should sync immediately whenever a change is made to ...
0
votes
0answers
21 views

Purge lines in a file based on age in shell script

I wanted to record the slave delay in mysql server every minute,so prepared a simple script. #!/bin/bash echo "`date` : `mysql -uroot -pXXXXXX -e"show slave status\G" | grep -i ...
0
votes
1answer
44 views

Is there a way to add lines to .bashrc without permission to access?

I have sshed into another computer, on which I’ll be working. In order to access the tools I need, I’m supposed to “go into my .bashrc file” and add two lines: eval 'path/to/file/setup.sh' AND source ...
0
votes
1answer
40 views

A few questions on using variables and files in for loops in shell scripting [closed]

I have this problem I need to solve. I barely use any Linux at work other than modify my rights on the AWS terminal so my knowledge is not great.I also have looked for quite a while and everything I ...
1
vote
0answers
15 views

Sed works standalone but not in command substitution [duplicate]

When I use the following command in Bash, it works fine: sed -n '/##/{p; :loop n; /##/q; p; b loop}' FILENAME.txt It outputs something like this: ## * Some line Command substitution However, when I ...
0
votes
1answer
32 views

Unable to run a bash loop in linux by taking two input files as an input?

Newbie to bash scripting, I made script to automate the program to run on 100 different files, can someone please correct the script. In a directory I had 1 to 100 files with suffix *_R1_sic.fast and *...
1
vote
1answer
34 views

What is wrong with this script that is supposed to test the Collatz Conjecture?

I want to make a script that tests the Collatz Conjecture. More specifically, the goal is to make a script that allows me to enter a positive integer that is not 1, and prints out the final number ...
0
votes
0answers
20 views

How to set a variable with name from another variable? [duplicate]

I'm writing a script in bash and I added these commands that will set names of 2 directories and count of these directories. dir1="name1" dir2="name2" count=2 Then, I made a ...
4
votes
1answer
39 views

How is this script (open-switch/opx-build/scripts/opx_run) passing variables?

Like many bash questions, I'm 100% sure there is an answer but Googling them is challenging. I'm trying to understand the following script: #!/bin/bash # available options export OPX_GIT_TAG="${...
0
votes
1answer
29 views

How to convert all text files in directory to one csv

I want to convert all text files in a directory to one csv file. I want the input to the csv to be the text in the text file labeled by the author of the text file found in the filename. For reference,...
-3
votes
0answers
19 views

How to find the top 3 process that was started in the last 10 seconds? [closed]

How to find the top 3 process that was started in the last 10 seconds using bash
0
votes
2answers
39 views

Switch all my git repositories to depth 20, to save space?

I know that git clone --depth=20 <repo> is oftentimes much much smaller than git clone. Official docs for --depth. Looks like I've gone a bit crazy with my repos folder, here's the fd piped to ...
-1
votes
2answers
35 views

Convert array into string

I have a string say, test_var=ab_c_de_fg_.txt. I need to store ab_c in one variable (characters before the 2nd _) and de_fg_ in a second variable (characters after the second _ and before .txt), so ...
2
votes
3answers
25 views

Using regex with IFS variable to split Bash string

I am trying to split a string into an array by any character that is not alphanumeric. Can assign a regex pattern to the IFS variable to accomplish this? I have tried it like so: input="$1" ...
0
votes
2answers
41 views

How to Get total number of bytes copied by SCP

I want to know total size of copied data from two different locations to another server using scp: scp /../folder1 /../folder2 srv2:/output/
1
vote
1answer
32 views

zmv (zsh) over ssh behaves differently between shell and script

I'd really appreciate help getting zmv to work as expected via ssh in a script. I'm trying to change filenames on a remote server over which I have full control. Both local and remote machines are ...
-2
votes
0answers
26 views

Script to search accross all folders and run a function for datasets

/opt/IBM/InformationServer/Server/DSEngine/bin/dsjob \ -run \ -param 'pInputDS=/dtdata/datastage/Projects/data/staging/rbcadr/posdaily/20190907/20190901.ds' \ -param 'pOutputFile=/dtdata/...
1
vote
1answer
28 views

Inserting into a Oracle table from a shell variable storing thousands of values

I'm trying to insert records into a column in Oracle where the values are passed from a shell variable. The variable itself stores pattern generated from a list of files. This pattern is generated on ...
-6
votes
0answers
40 views

How to transpose below pattern using bash script? [File-1 --> File-2] [closed]

How to transpose below pattern using a bash script? I want to convert File-1 to File-2: $ cat File-1 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 $ cat File-2 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
4
votes
2answers
514 views

Why does [ -d $dirname ] match when the variable is empty or unset and why does this result in the contents of the home directory being deleted?

Well I've this code dirname= if [ -d $dirname ]; then cd $dirname && rm * fi as you see I've this empty variable, what I want to know is why when using thing like this empty variable with ...
0
votes
1answer
53 views

why tcsh script choke on special characters inside file eg. #{ on a line is giving missing “}” error

I'm using tcsh shell script to read each line of a file input.txt script #!/bin/tcsh set out_file_length=`wc -l<$1` set i=1 while ( $i <= $out_file_length ) set each_line = `head -$i input....
0
votes
0answers
14 views

need to collect files with ceratin name and date from remote multiple servers

I need to write a bash for collecting files from remote servers with certain name and with certain content i.e i will grep content of those files and I need all this files to my server from which i ...
0
votes
1answer
18 views

How to I set document ID or ID to PDF file via terminal?

Hello I am writing a bash script, this script must give ID to pdf file. How do I solve the this, is there a way? Example as using bash shell. Document ID is: $ exiftool example.pdf | grep 'Document ID'...
1
vote
1answer
31 views

script to delete all files smaller than certain size (cron job)

I need to delete all files smaller than 13MB in /media/motion AND all files with the same filename with an extra extension appended to it (that are all much smaller than 13MB) so I append '*' to the ...
1
vote
1answer
65 views

UNIX KSH - Using double quotes or no quotes when assigning strings with wildcard to a variable?

I am new to UNIX and currently working on a shell script where I will be receiving files with names such as abc_123_date.zip so the file names will be abc_123_12312005. Instead of hardcoding abc_123_*....
-2
votes
2answers
107 views

What does the `-eu` mean in `#!/bin/bash -eu` at the top of a bash script? (or any of `-abefhkmnptuvxBCHP`)

What does the eu mean after #!/bin/bash -eu at the top of a bash script? Normally I begin my bash scripts with this hashbang/shebang: #!/bin/bash but I just came across one with #!/bin/bash -eu and ...
2
votes
2answers
70 views

remove a set of identical lines from a set of files in a directory

I have a drupal website, which exports its configuration into yaml files. For its webform component, we have some 200 webforms that blind-carbon-copy submissions to an internal email address, to track ...
0
votes
1answer
18 views

Shall script to execute a script on a seconds server and then resume original server [closed]

On server 1 I have a script that runs a script on server 2 via: ssh root@server_ip /script/script.sh Once the script has finished on server 2, I exit and at this point I would like to resume the ...
4
votes
2answers
146 views

Input redirection to for and while

Just out of curiosity, This command works: $ <file cat But neither of these do: $ <file for bash: for: command not found... $ <file while bash: while: command not found... Why is that?
-5
votes
0answers
36 views

How command substitution and redirect works? [closed]

I'm trying to understand how can I loop through files and literally over anything I want to do using command substitution I assume... What I don't understand yet is: read -r in for loops or while ...
0
votes
1answer
32 views

Check file exists with dynamic name [closed]

I've a file with dynamic name with version like Abc.1.0.zip, Abc.2.0.zip. I want to check if file exists irrespective of version. I tried find -name "Abc(.*).zip" But this does not consider ...
0
votes
2answers
48 views

Break a long command to multiple lines

I got a shell script and inside I got the command as below #!/bin/sh sh ../jboss/bin/standalone.sh --server-config=standalone-full.xml -Djboss.node.name=node1 -b 0.0.0.0 -bmanagement 0.0.0.0 How can ...
2
votes
1answer
120 views

Bash array access not working as expected

I am re-writing code to work with a newer system. I did not write the original code, but I'm trying to use the old code as a template. When I run the command by itself, it works fine. When I try ...
2
votes
1answer
36 views

identify process sending a signal to a shell script

I've written a shell script that uses the trap feature to output its progress when it receives a SIGUSR1 signal, but I don't see how to have the script be able to output the progress to the STDOUT of ...
0
votes
1answer
54 views

How to strip off certain hexadecimal characters in Bash?

I have gathered a wordlist for person to follow on twitter. However, there is a problem. When i cat and do xxd a extra hidden characters are found. i.e 1b5b 6d1b 5b4b . I need to strip those character....
0
votes
1answer
32 views

Shell script to check existence of multiple strings in a file

I have 3 strings A='apples' B='bananas' C='carrots' I want to see if all of these exist in the fruit.txt file. If I'm missing A then add A, B then add B, and so on. This is what I have now if grep -...
0
votes
0answers
66 views

Why do I receive intermittent I/O Errors that say “Couldn't open text file” when using pdftotext while looping through directories?

I have a bash script with a loop that uses pdftotext to convert many pdfs to text. Below is the relevant portion of the code: cd /data/user/Data/Reports/pdf/ dirs=(A*/) for directory in "${dirs[@]...
0
votes
0answers
29 views

how could I sort hundreds of images by their content

I m looking for a solution to sort hundreds of images by their content; of course, I will script around the solution to automate that work. I know I can use metadata to separate draws and photos. But ...
-4
votes
2answers
42 views

Taking a specific part of the file name with shell script and put into loop

Let me explain, .SAC files are type of seismograms which SAC ( Seismic Analysis Code ) program use and the other files which contains *HH are response files. I want to remove insturment response which ...
0
votes
1answer
22 views

SSH Time out Error

I am looking for new ideas on how can I do more better. Home laptop (home Laptop can access only Linux VM) Linux VM (This machine can access only jump box) jump box VM I can ssh fine from Linux VM to ...
2
votes
2answers
78 views

How to add text to the end of the result of a command

I have a command that I use on a script and it is working well. I need to append some text to the result of that command. Command: ssh target_server "/home/directory/somescript.sh" | tail -1 ...

1
2 3 4 5
261