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 [scripting]

A script is a sequence of commands or instructions that are executed by an interpreter program rather than compiled into a standalone executable program.

-2
votes
2answers
25 views

Replace a variable with stdin?

I want to loop over some values and I know I can simply use a for loop but is there any other way that I can replace a variable value in a command at the end of the command? Somewhat like echo 11"$...
1
vote
1answer
32 views

Linux - case command - How to have spaces or tabs in the menu list?

I don't know why, but a can't find the answer anywhere. I suppose that it's a very simple change. PS3='Please enter your choice: options=("Option 1" "Option 2" "Quit") select opt in "${...
-2
votes
0answers
25 views

BASH Creating a unique username [on hold]

I originally posted the question here... Unfortunately, there is no way for me to reply to answers, so I made this one. Feel free moderators to delete the original post. I have a textfile called "...
0
votes
2answers
31 views

Find number of cores available in a given node

I need to fix the following piece of code. The code aims to determine the number of cores available in a given node. Step 1: Get the number of cores with TC=$(grep -c process /proc/cpuinfo) Step 2:...
0
votes
1answer
57 views

Input from readline owerwrites the prompt

So I'm trying to create an interactive bash script, where i can call given options from 1-n or just them like commands. It will end up with a simulated prompt and 'read' is used to get the input, ofc....
-3
votes
1answer
67 views

Delete files that are older than x number of days [duplicate]

I have a situation where I have to clean up files that are older than 7 days, but from multiple locations like below. /home/user1/Out/vendor /home/user2/Out/vendor /home/user3/Out/vendor /home/user4/...
0
votes
3answers
60 views

Syntax error near unexpected token ` | '

I keep getting this error line 3: Syntax error near unexpected token `|' This is the script at the moment: for filename in $(ls $1) | grep -v ".old" do mv "$1/$filename" "$1/$filename.old" done ...
0
votes
2answers
19 views

Figuring out the remaining seconds left until a certain time with bash?

I'm thinking about extracting the time from the 'date' command, subtracting a certain time in the future from it to get the number of seconds left until 'date' reaches that time, then to divide that ...
2
votes
1answer
15 views

How to reference an array with a function prior to bash4.3

If we: Define an array; and then.. Define a function; and want to.. Call that array from inside the function.. We can. Like so: Input: myArray=('1' '2' '3' '4' '5') myFunction () { local -n ...
0
votes
0answers
21 views

log monitoring & alert [duplicate]

I have to create a bash script that is doing the following: compare the date/time log against the current date/time on the server. If there are no logs on the server in the last 10 minutes, send an ...
0
votes
0answers
25 views

Script to create virtual machine [closed]

How can I create a script to automate the creation of a virtual machine and install packages on that machine(eg. Zabbix modules)? Do I really need an ubuntu disk image to create a virtual machine or ...
1
vote
4answers
47 views

Add Space Before Last Character in Variable

I have a variable that contains some numbers then a letter example: 242M I need to add a space right before the last character in that variable so that when echo'd it would look like 242 M I've ...
0
votes
2answers
30 views

Using source command in script but defining the input file in the command line of a terminal

I have a script at the moment that reads in variables and then operates on them like the following; #!bin/bash a=10 b=15 c=20 d=a*b+c echo $d However I would like to split this up into an input ...
0
votes
3answers
35 views

remove last number from string

I have a file test.txt, below the content: SCDE1 SF9 STR1D2 SREDF21 FRED STER2R4 I want to remove only the last character if it is the number, so the output should as below: SCDE SF STR1D SREDF2 ...
-1
votes
0answers
33 views

Script program question - Extracting information from log file [duplicate]

So I am currently making a script for a class of mine where we created a menu with three options and wait for the users input. The log file that we are extracting information from currently looks ...
-1
votes
1answer
74 views

Why does this for loop ignore my variable? [duplicate]

I am trying to do a simple script which runs a few commands N number of times, determined by the user's input. However, when it comes to run the commands (in a for loop) - The variable is ignored: ...
-3
votes
0answers
17 views

bash script to check an email box by sender and subject and then set a monitoring status alarm [closed]

I would like to write a bash/shell (on gnu linux) script that checks a certain email box by: sender, subject, and then if the sender and subject is "x" and "y" it should return a monitoring tool code (...
1
vote
1answer
11 views

How to extract data from csv file with modification to data

For eg i have a file called test.csv containing emp1,dep1 emp2,dep2 emp3,dep1 emp4,dep3 emp5,dep2 expected output is emp1 works in dep1 emp2 works in dep2 . . emp5 works in dep2
0
votes
1answer
19 views

How to replace an entire paragraph in a file?

I want to change this: ... %%%23begin aaaaaaa \\ bbbbbbb \\ ccccccc \\ %%%23end ... to this ... %%%23begin xxxxxxxx \\ yyyyyyyy \\ zzzzzzzzz \\ tttttttt \\ %%%23end ... the number ...
0
votes
1answer
24 views

Counter in seperate text file

I have a script that processes files based on drop folders, I created a function to do the processing and based on a set of variables I process a folder funtion filedetect { // <some processing ...
1
vote
1answer
23 views

Read string block as multiple variables ubuntu

I have a script to copy permissions which works fine, being the interesting line this one: ... bash commands.sh $PAM_USER "medium" /bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed} /usr/bin/{vim,touch,...
-2
votes
0answers
38 views

Shell script that serves as a checklist [closed]

I have to write a shell or bash script called "valid" that validates a handed project. For example, the name of the project to be validated is: project.md This file is supposed to be the same ...
1
vote
1answer
40 views

Ping - big packet size problems

I have some problems with pinging hosts with big packet size. I'm doing some research on latency between one configuration and another. I have written bash/zsh script to make it simpler that pings 8....
2
votes
1answer
50 views

Find duplicate String inside a text with middle near each other

I need to find a string of 13 character length in a text file that has a duplicate close to it. It referencing to the mutation 13 of the genomes. For example: ACGAATTGCAGCCACAGTACGAATCGCAGCC. It ...
1
vote
0answers
23 views

Script continues execution after call to gnome-terminal [duplicate]

I'm using bash to run a terminal which launches a few programs in separate tabs. However, after the terminal opens, it seems like my script continues even though generally this only happens if we use ...
1
vote
2answers
132 views

elif condition in an if statement

I have this variables start=$1; end=$2; sn=${#start} en=${#end} and this if : if ( [ $# -eq 2 ] ) then elif ( [ $sn -ne 3 ] && [ -n "$(printf '%s\n' "$start" | sed 's/[0-9]//g') " ] ); ...
0
votes
1answer
24 views

Taking two integer arguments (the first smaller than the second) print out lines between the two integer arguments

I have a list of the most common passwords and their frequencies . It is a long list and it is formatted as such: 59462 password 49992 iloveyou 33919 princess ... 30 yahoo123 To be clear, the ...
0
votes
2answers
61 views

java -version In Bash Script. Giving integer error

I am trying to make this if..fi case work for the Java Version from wrapper.conf configuration file./ and from the system, If the output from wrapper.conf is java I would have two options; 1. ...
0
votes
3answers
52 views

find log files recursively and print “INVALID” if no log found (bash)

I have ~750 log directories I need to search for the latest log file available: These are captured by the allLogs.txt file and each entry contains a wild card '*' so that ONLY the log with the latest ...
1
vote
2answers
36 views

Return value from nmap IP address only and pass it into a loop in Bash [closed]

I have this script of nmap which retrieves only alive IP devices from the network. nmap -sP 192.168.1.0/24 | awk '/is up/ {print up}; {gsub (/\(|\)/,""); up = $NF}' I want to get the result IP ...
-1
votes
2answers
64 views

Linux + how to capture the OS disk device [closed]

we want to capture the disk device that belong to the OS ( Linux ) since each linux machine have list of disks that are not the OS , we want to capture the disk that belong to the OS so by fdisk ...
-1
votes
1answer
83 views

RHEL: syntax errors with bash script

I was tasked to do a bash script that can audit logins in mysql. If you activate the general_log option in /etc/my.cnf, you can register all the activity that mysql does and it get write (in my case) ...
1
vote
1answer
32 views

How to write a function that reliably exits (with a specified status) the current process?

The script below is a minimal (albeit artificial) illustration of the problem. ## demo.sh exitfn () { printf -- 'exitfn PID: %d\n' "$$" >&2 exit 1 } printf -- 'script PID: %d\n' "$$" ...
-6
votes
0answers
16 views

bash script make [duplicate]

I have a script called myscript.sh who gets arguments in the command line, and i want to decide which ones are integers in base 10 and display: Numbers representing a power of 2, one per line, in the ...
0
votes
1answer
48 views

Check pow of 2 with restriction [duplicate]

I need to write a condition so if the argument is 1 ( which is 2 ^ 0 = 1 ) it will jump over it. For example: powsnsums 1 2 8 2 powsnsums 1 16 1 #!/bin/bash # loop over all numbers on the ...
0
votes
3answers
87 views

Sum of command line arguments?

How would I create a bash script that the user can use to sum any amount of command line arguments, but it will also ignore incompatible arguments? For example, say my script is called sum: sum 10 -...
0
votes
0answers
13 views

From guake, pass command to gnome-terminal to kill and respawn guake

Background I have tried to provide an answer to Restart Guake inside Guake. So far, I have achieved to: create a gnome-terminal deamon, from guake: screen -dmS other_terminal gnome-terminal kill ...
2
votes
2answers
164 views

How to write regexp literal in match expression?

This question is about the proper way to write regular expression literals in a match expression under bash. In zsh, the match below succeeds, as I expected: % [[ ' 123 ' =~ '^ [0-9]+ $' ]]; echo $? ...
-3
votes
2answers
87 views

Calling sh with script on stdin and passing command line arguments

This works of course. I can run ./test1.sh cats and the argument cats is passed correctly to ls. $ cat test1.sh #!/bin/sh ls -l $1 Can you tell me how do I make this second example — the same ...
-3
votes
1answer
34 views

How can I print the memory usage in KB by free?

I need to print the RAM memory used at this time in kilobytes(KB) with command free, how can I do that with one line command input: free ... output: 567595 output should be contain only kilobytes ...
0
votes
0answers
21 views

Service to mount USB cannot mount USB

I have a small watcher I am deploying to detect when a certain USB stick is inserted on SLED 11 (Suse) terminals. It should then mount that stick and read some files on that stick. Problem is - I ...
2
votes
1answer
32 views

How can I sum the time based on usernames?

Basically, I want to see how much time every user spent logged in. (username) pts/0 (IP adress) Tue Dec 12 17:51 - 18:14 (00:22) - this is how one line looks in the last command. The ...
0
votes
0answers
31 views

Bash script optimization (PDFTK + grep…)

The next script grabs all PDF files within a folder, and then for each one, it splits in several small files based on a certain criteria, using pcregexp to fetch that criteria. Then it compress the ...
1
vote
2answers
51 views

How can I output NUL correctly to a file via a script?

$ FILE="$(mktemp)" $ printf "a\0\n" > "$FILE" $ od -tx1z "$FILE" 0000000 61 00 0a >a..< 0000003 So far so good. I wrapped the above into a bash ...
0
votes
1answer
41 views

sed? - replace part of line if match from another file found

I need to take one file containing lines same as this fake one: 232.232.232.256:2001, 232.200.200.256:2314 And i need to run trough another file *.json, and find all occurrences of first "IP" and if ...
-3
votes
0answers
63 views

bash script for work [duplicate]

i want to make a script who gets arguments in the command line, decide which ones are integers in base 10 and display: Numbers representing a power of 2, one per line, in the order received. (Do not ...
0
votes
1answer
82 views

Trying to generate random password characters into a file

I want to generate 100 files with 100 random passwords in /mnt/mymnt/passwords using a script creating some directories. Even if i try to use cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 30 | head ...
0
votes
1answer
43 views

How can I write a shell script to filter the last command?

I want to write a script for login statistics. I want to count how many times a user logged in, and then display them in ascending, or descending order, given by the end user. The problme being, i don'...
0
votes
1answer
24 views

delete folders with the same name as the parent folders recursively in bash?

So some file copying went wrong in one of my machines and I'm wasting a ludicrous amount of space by having a copy of each folder inside of the parent with the same name, and i'd want to delete them ...
-3
votes
2answers
50 views

Write a script that accepts [closed]

Write a script that accepts two arguments, the firs represents a prefix string, the second a path (assume that it is an absolute path). Where the script you write must do the following If the user ...