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.).

0
votes
1answer
16 views

sh script for executing mysql script with entering pass

Hi I am a total newbie so please excuse me if what I ask seems rediculios I'd like to execute a mysql script where user is asked to enter the password dynamically from the command line. If possible ...
2
votes
1answer
105 views

adduser Firstname.Lastname

I tried to use both useradd and adduser to get a username typed as Firstname.Lastname. I tried also installing libuser and using luseradd, but also I got error. Is there a way to do that (of course it ...
-4
votes
0answers
27 views

what is the difference between reading a file using cat vs echo [on hold]

how does the terminal handle a file when you run it through cat and echo: example how does it read, cat file | foo vs echo file | foo, do different processes open and read them, does the foo command ...
2
votes
1answer
19 views

Calling clipit from inside a shell script

I am trying to launch clipit from inside a script using i3wm and polybar. I expect it to relaunch polybar and start all the programs I wanted if they're not already running when I reload i3, but ...
0
votes
1answer
43 views

CLI equivalent of Gnome's recent files feature

In Gnome's File manager (Nautilus), there's a feature called "Recent Files" which presents itself like a "virtual directory" of sorts, listing the most recently created/modified files in the user's ...
-4
votes
0answers
32 views

How to grep a second pattern and print the line till the next third search pattern [on hold]

How to find or search PATTERN1 and then search PATTERN2 and print them both later i want to search PATTERN3 and Print the whole content or section between the search PATTERN2/PATTERN3 (Note Pattern1/...
1
vote
0answers
13 views

Get the path of song playing in VLC using python script

I am trying to get the path of song playing in VLC using python script. I have already find out the Process ID of vlc using pgrep -x vlc And I can also display the all file descriptors of vlc ...
-4
votes
0answers
42 views

Error in an if…else statement [on hold]

I tried to execute the script (below), but it didn't work. Any suggestions on how I can make this script work? Is this the right way to use if....then statement inside the script? date=$(date -d '0 ...
0
votes
2answers
28 views

Shell Script\, display directory listing to option input / trying to select two files to compare

I am trying to have the user select two files from a numbered list which is derived from a directory listing and will eventually be turned into a variable. This is probably something simple and stupid ...
1
vote
1answer
51 views

Xargs rm doesn't work when running it in a script as part of a core_pattern

I am trying to run a cleanup script that gets invoked on every core dump. I first wrote the contents of the core file to another file, and after then I tried to do a cleanup on the oldest two files. ...
0
votes
2answers
45 views

How do I use 'expect' to read the contents of a file into a variable?

I am having troubles writing an expect script. I want to do something equivalent to the following bash instruction: iplist=$(cat iplist.txt) I've tried using set in all the ways that I know but it ...
1
vote
1answer
25 views

What is the significance of '+' in this statement. if [[ ${array1[$i]+DEFINED} == 'DEFINED' ]]

Would you please help me understand What is the significance of "+" in the following for loop: for i in $*;do if [[ ${array1[$i]+DEFINED} == 'DEFINED' ]];then command1 fi done
0
votes
2answers
28 views

Check a file is created on current month

I have a file in directory, I have to check whether the file created on current month. I'm trying a solution in shell script. Ex: my file path is data/tmp/docs/test.txt, I just wanted to check the ...
1
vote
1answer
26 views

Makefile: Default Value of Variable that is set but has null value

I have a Makefile that has a variable that needs to have a default value in case when variable is unset or if set but has null value. How can I achieve this? I need this, as I invoke make inside a ...
0
votes
1answer
36 views

Perl Script Output in Excel / Text file in Solaris 10

I have a perl script, I am not able to get output of script in an excel or text file format. Can someone please help me figure out that ? perl -MPOSIX -e ' opendir D, "." || die "open .: $!\n"; ...
0
votes
1answer
21 views

Pass parameter to a different bash shell

I have written a bash script Script1.sh #!/bin/sh read -p "Enter name of the document file :" name read -p "Enter LHOST :" lhost read -p "Enter LPORT :" lport echo "use exploit/...
1
vote
2answers
39 views

Not able to replace String while reading the file

The final.txt looks like: build/create_changes.sh build/create_changes.sh-meta.xml src/aura/camping/camping.design src/aura/camping/camping.design-meta.xml And the code looks like this: if [ -e ...
0
votes
3answers
53 views

Text selection in Unix using sed

I want to select a particular part of a text file and print it / store in another file. Selection starts when a particular pattern matches and ends when another pattern matches. And I have to do it ...
0
votes
0answers
39 views

/dev/tcp response read works on command line, but hangs as script

I am stuck because of a puzzling behavior I cannot figure out. I am testing a (java) daemon listening on a local socket (5300): I establish a client connection via /dev/tcp on bash and expect to ...
1
vote
1answer
35 views

fastest way of searching for a text in a file (not file name) including the root volume [duplicate]

Which is the fastest search method in linux to search (only) for a text inside whole linux file system (NOT JUST A SINGLE FILE) the search needs to be performed on all the files including the root ...
3
votes
2answers
28 views

Group rows in one file based on column value

I have "csv" spreadsheet as below abc,12345,qwerty,A xyz,12380,qwetty,R abc,12389,qwerty,A xyz,12324,qwetty,R I would like to combine rows with similar values in columns 1, 2 and 4. Also, i would ...
0
votes
1answer
28 views

Changing two strings on same line matched by a regex

I have a number of variables in a .dat file that I automatically changed with a script. One of these files has a parameter, bar, that is arranged as such in a .dat file: var1 var2 var3 foo bar T ...
35
votes
8answers
4k views

One-liner to generate an easily memorable password?

What's a good one-liner to generate an easily memorable password, like xkcd's correct horse battery staple or a Bitcoin seed? EDIT 1: This is not the same as generating a random string since random ...
-1
votes
0answers
48 views

Bash - nesting quotes - three level quotes

I prepared a bash code to the Xfce menu item in the launcher. Before putting it to the launcher I tested it in the terminal. I worked well. To put it into the launcher I had to put it into the ...
0
votes
1answer
20 views

tar -C with certain files in the direcory [duplicate]

Let's say I have two directories that I would to tar without retaining the directory structure: /root/dir1 /root/dir2 Also, I would like to backup only files that begin with say f1 in /root/dir1 and ...
0
votes
0answers
31 views

Wrap a cron job around a script which queries MySQL tables on host [on hold]

I have an input.sh script which basically connect to mysql-db and query multiple tables to write back the output to the output1.out file in a directory. I would like to pass an integer (unique_id in ...
0
votes
0answers
17 views

shell script to scan ebs volumes for a text

I have a requirement, where I need to search the attached aws multiple ebs volumes on a Linux Ec2 instances for certain text. For example below are the disk attached. Any help is greatly appreciated ...
0
votes
2answers
33 views

Rename a csv tab from UNIX bash script

I have CSV file that is generated from a bash script: UNIX_REPORT.sh. When you open CSV the file on the windGrr side with excel, the tab (or sheet) in the lower left corner is named UNIX_REPORT.sh. ...
5
votes
6answers
308 views

Loop over lines in file and subtract previous line from current line

I have a file that contains some numbers $ cat file.dat 0.092593 0.048631 0.027957 0.030699 0.026250 0.038156 0.011823 0.013284 0.024529 0.022498 0.013217 0.007105 0.018916 0.014079 I want to make a ...
1
vote
3answers
44 views

How to login to mutiple servers in a loop

I have a script called script.sh. I want to execute it on various machines like host1, host2 etc. How to loop each server by passing user name and password ?
0
votes
1answer
25 views

Copying full components from a folder to another, throwing bad substitution

The final.txt looks like: build/create_changes.sh build/create_changes.sh-meta.xml src/aura/camping/camping.design src/aura/camping/camping.design-meta.xml I would like to replace only replace the ...
0
votes
0answers
26 views

Unable to restart network-manager from a script when run as a cron job

I have Ubuntu 18.04 and sometimes (some wifi connections) my network just stops working. What I have been doing so far is when that happens I just restart network-manager and it starts working fine ...
0
votes
0answers
17 views

What are the “ ”s in this Mkinitcpio of Encrypted Dm-Crypt Guide To Indicate

Recently, I reinstalled a distribution of Arch Linux using a removable disk. Within the custom encrypt hook file I came to an impass as far as being able to discern exactly what is meant when adding ...
3
votes
1answer
122 views

Scheduled folder backup

I'm looking for how to automatically backup a user's home directory in CentOs 7 to a remote host or NAS or just to ~/.snapshot. In some Linux setups, I have seen a .snapshot folder in the user's home ...
0
votes
2answers
37 views

How can I iterate over files in a given directory, and check if file exist?

Here is the files list in a given directory; a_object_1.0.zip file_name_conf_1.1.zip anim_dup_1.1.zip Iterate over files in a given directory, and check if file matching the file pattern from the ...
1
vote
2answers
35 views

Importing environment variables from another script into the current shell

I have a shell script that sets some environment variables that I run through the source command to affect the current shell. I created another shell script that refers to this shell script and I ...
4
votes
2answers
162 views

How to suppress stdout / stderr from a shell script output?

I have a script that is suppose to stop and recover the process to run in the background: process_id=`ps -eaf | grep -i daemon | grep -v grep | grep -v status | grep -v stop | awk '{print $2}'` (kill ...
-1
votes
2answers
22 views

print matched lines when column 6 or 7 is greater than 90%

I have data in a text file something like below. server volume available total used percent-used percent-vol-space --------------- -------------------- --------- ------- -----...
1
vote
1answer
35 views

Teaching assistant bash script to automate the process of finding, compiling, and running .java files [closed]

Here is a copy of my current code: #!/bin/bash list="/Users/ajm/Desktop/170Grading/output/list.txt" score="/Users/ajm/Desktop/170Grading/output/score.txt" echo "" > list echo "" > score find $1 ...
-2
votes
0answers
16 views

rsync files in special subdirectory and subdirectory changes over time! [closed]

This is directory tree and its feature! /home /backup /sound /0121----This directory automatically creates a folder named by the current date every day,0121 represents January ...
0
votes
2answers
18 views

Find with absolute path inside a bashscript | xargs basename

I have to find recursively inside a bash script. Since I can invoke the bash script from anywhere, I am forced to use the absolute path. Sometimes the absolute path can get very long, and the output ...
0
votes
1answer
25 views

Write script to generate report on every Thursday [closed]

On every Thursday we have to send the report like below for 18 servers Account: swebwpsp Server name: nykpsr17896 Disk space usage: 70 % (we use df -kh command) Date: 20-09-2018 Similarly we have 18 ...
-2
votes
1answer
21 views

Need shell script to read line with matching content

I have an abc.txt file it is having 100 lines. I wanted to read the specific content from that 100 lines and print that matching line. Below is the text file. 2018-09-12 11:00:02.290 [main] INFO ...
1
vote
2answers
56 views

Can you nest remote calls using ssh in a bash script? [duplicate]

I have run into a strange issue that Computer A can see Computer B, Computer B can see Computer C, but Computer A can not see Computer C. I would like to make a bash script that can be run on A that ...
3
votes
1answer
53 views

Using a bash array in an awk and also quoted variable: conflicting syntax issue

I have a script the aim of which is: For a list of files, obtain a specific number for each file (this is sequencing data, to be specific) and store these into array1 Using array1, find the smallest ...
1
vote
0answers
48 views

touchpad not working after hibernate

I'm using an up to date Arch/Antergos Linux. My touchpad stops working after resuming from hibernate. I seem to be affected by this bug and I need to type sudo rmmod i2c_hid; modprobe i2c_hid after ...
3
votes
2answers
29 views

Concatenate multiple zipped files, skipping header lines in all but the first file

I have a collection of gzipped files that I want to combine into a single file. They each have identical format. I want to keep the header information from only the first file and skip it in the ...
-1
votes
1answer
57 views

Bash loop for detecting equal folder sizes

I would like to detect when the transfer of a large amount of files is completed. I would like to accomplish this by detecting the size of the folder with a time delay. Below is what I have done, ...
3
votes
2answers
46 views

Shell script to autostart script

I would like to refer to my previous post here: Autostarting a python script whenever it crashes to restart two python scripts on my raspberry pi (Stretch OS) if they crash. The code of the shell ...
1
vote
2answers
47 views

How do I search a file for a pattern, then extract part of the pattern or supply a default if the pattern does not exist?

I'm trying to write a script that searches through a pre-made list of running processes across a series of machines. I'm specifically looking for rsyslogd running on those devices, and attempting to ...