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

learn more… | top users | synonyms (2)

2
votes
4answers
155 views

pulling lines related to the date

I've got a text-file that's sorted by the first field, which is month/day (eg: 02-20) I've been using grep on rhe text file, but that's easiest to do with today's date, using the date command in a ...
0
votes
1answer
54 views

How can I use sed to find a string and replace another string on a different line? [closed]

I have a file like this: BEGIN Name "TIPO_RECORD" SqlType "12" Precision "255" Name "Test" SqlType "12" Precision "255" Name "xxxx" SqlType "12" Precision ...
0
votes
1answer
30 views

sending mail for frequently changing users

I want to use a control file where I have all my mail Ids stored in a directory say Ex: /abs/pqr/send_mail.ctrl Sample of control send_mail.ctrl abc@domain.com str@domain.in ------ ----- Now I ...
1
vote
2answers
66 views

Prevent certain lines of a script to run as root

Suppose I am writing a shell script that requires root privileges to run, for example- #!/bin/sh ip -s -s neigh flush all ufw enable How can I prevent certain lines of code to be run as root, i.e. ...
3
votes
2answers
169 views

Whats going on in this function?

log () { A=$1 print "`date '+%m/%d/%y %H:%M:%S'`: $A" >> LOGFILE.txt print "$A" } This is how log function used in most of the shell scripts in our environment. and its been used in ...
3
votes
2answers
380 views

Script for changing modification time of files and directories recursively

I have many big folders with thousands of files in them and I want to use touchto set their modification times to be "original time"+3 hours. I got this script from a similar thread in superuser: ...
2
votes
2answers
250 views

How to make this `echo | bc` output be on the same line as the echo output after?

I'm making a program for generating random numbers, and before it generates, I want to show how many combinations there are. When I do it, I get this: 64k@conroe$ bash random A-Za-z0-9 3 238328 ...
2
votes
3answers
996 views

extract string between double quotes

I have requirement that i need to extract string using quotes. My string as follows. "abcd efgh" "ijkl mnop" "qrst uvwxyz" can you help me to get the string between second double quotes(ijkl mnop) ...
6
votes
1answer
1k views

Bash substitution with variable defined from a glob pattern

The below example explains the issue. Why is the FILENAME printed correctly when echoed and perceived as a pattern when using substitution? #!/bin/bash FILEPATH_WITH_GLOB="/home/user/file_*" ...
2
votes
0answers
59 views

“: not found” and syntax error in my first ever shell script [duplicate]

The shell script, I am trying to create, should be run by crontab regularly, and it should call a perl script which saves email attachments to a predefined directory. Here's what I came up with: ...
1
vote
1answer
324 views

Problems with kpartx in a script

I am trying to run the rpi-image-creator script (see https://github.com/ImmobilienScout24/rpi-image-creator/blob/master/rpi-image-creator), and encounter some trouble with the kpartx use. The trouble ...
1
vote
1answer
111 views

Bash script to connect to Teletalk internet

I'm running Elementary OS(based on Ubuntu 12.04), and I have to connect to the internet in a peculiar style. I use a Teletalk modem to connect to the internet. Unfortunately, the modem gets recognized ...
4
votes
4answers
936 views

How to insert all lines from one file to another file?

File1: .tid.setnr := 1123 .tid.setnr := 3345 .tid.setnr := 5431 .tid.setnr := 89323 File2: .tid.info := 12 .tid.info := 3 .tid.info := 44 .tid.info := 60 Output file: .tid.info := 12 ...
1
vote
1answer
51 views

How can I execute and interrupt a script in a loop

I have a script called demo.py First I execute the script python demo.py -some arguments After some time (let say 120 seconds) I interrupt it with Ctrl+C and execute again. Can I write a bash ...
1
vote
1answer
107 views

Coloring a `cat` output?

I'm trying to practice code and integrating my other interests with it, and a strong interest of mine is genetics/science in general. I'm making a simple script to generate a random string, but if I ...
0
votes
2answers
45 views

filtering files from search

I have some files containing date and timestamp which I want to exclude from the output of ls as in: test.log.15-05-25_20:41:05.20150611 test.log.15-05-27_20:28:32.20150611 ...
0
votes
4answers
87 views

tabs in variable not working

I have this lines that i will insert in a mail called "header". header=" ------------------------------------- Name\tAge\tGender\tAddress ------------------------------------- " Unfortunately, the ...
1
vote
3answers
107 views

Delete entries made in a configuration file [closed]

There are entries in a file as stated below define {line1 line 2 line 3 . . .. } define{line a line b line c . . .. } and many more are defined in similar way so, here I would like delete one ...
0
votes
1answer
74 views

Enable user login, there by login can happen either as root or user based on requirement

I am working with a board and when it finishes the boot, it gives us login as root user. What I want to do is to login as user or root based my requirement. Mean when the board boots up i should get a ...
1
vote
1answer
2k views

How to activate Virtualenv when a Python script starts?

I want to schedule a python script to run using cron on certain dates, the problem is that in order for example.py to work, example-env has to be activated, is there a way to make example.py activate ...
5
votes
5answers
1k views

How to delete files from a folder which have more than 60 files in unix?

I want to put a script in cronjob which will run in a particular time and if the file count is more than 60, it will delete oldest files from that folder. Last In First Out. I have tried, ...
3
votes
1answer
706 views

Regex for crontab validation

I need to check in bash whether an entry into the crontab file is valid. Is there a crontab command switch? I can extract individual lines and try to control individual items through regex. But I ...
0
votes
0answers
88 views

How to prevent wpa_gui from minimizing to systray after closing its window

The issue with wpa_gui I have nice networking setup of wpa_supplicant roaming + dhcpcd autoconfiguring the interface, both running in the background. It works very well, but the issue is with the ...
4
votes
6answers
3k views

How to keep last exit status after test

Is it possible to keep the last command exit status ($?) unaltered after a test? E.g., I would like to do: command -p sudo ... [ $? -ne 1 ] && exit $? The last exit $? should return the ...
1
vote
1answer
84 views

echo a colored text with tabs

I have the line below to echo values with tab between them. The text is also colored, however, some\t does not work. The output of this one below will have the first two \t not working. echo ...
1
vote
2answers
89 views

shell or perl script to check group have read privileges

ls -l drwx------ 8 ws web 1024 Apr 29 2013 abc drwxr-xr-x 8 ws web 1024 Oct 19 2011 def I need some script to find directories like abc which doesn't have read/execute permissions ...
1
vote
4answers
192 views

How to insert lines from one file to another file using shell commands?

I want to write 8 lines from file1 at the beginning of file2. My file1 contains the following lines: $BQ { VOL @home } database daba relation tcdeatid copy 1 { ...
4
votes
4answers
96 views

Echoing something with multiple quotes and key characters (&, $, !, etc.)

Let's say you have to echo this into a file: RZW"a4k6[)b!^"%*X6Evf How do you do it? My actual "line" to echo is a 2048 characters line.
1
vote
4answers
307 views

Unix bash/ksh : Selection of first non space character from file from specific line

I have file file1.txt whose contents are as follows: Date List ----------- Quarter Date Year Date Month Date Now I want to read the non space elements from each row of ...
17
votes
3answers
4k views

Understand “IFS= read -r line”?

I obviously understand that one can add value to internal field separator variable. For example: $ IFS=blah $ echo "$IFS" blah $ I also understand that read -r line will save data from stdin to ...
2
votes
3answers
88 views

Truncating the precision of a date

I'm working with a bash script which polls build progress from several different systems. If a build is complete, it stats a log file to find out the last time it was edited, then feeds that time into ...
0
votes
1answer
3k views

systemd Failed at step EXEC spawning /opt/autologger/placeholder.sh: Permission denied

This is a really simple question, I know, but I am jumping right into systemd with little prior knowledge of system management and Linux in general. I am attempting to create a "Hello World" service, ...
0
votes
2answers
250 views

expect: does “” (spawn_id exp70) match glob pattern

I have written an expect script that works perfect for testing passwords on our network until it has looped through my list quite a bit, then the debug output shows that there is nothing to match. ...
4
votes
3answers
319 views

Format column-based text file into tree structure using bash

Is there a Unix/Linux command that can turn this: AMERICA USA NEW_YORK AB-100 AMERICA USA NEW_YORK VF-200 AMERICA USA NEW_YORK XY-243 AMERICA USA LOS_ANGELES UH-198 AMERICA CANADA TORONTO ...
0
votes
1answer
182 views

bash script failing to use ssh -i. Can't see directory

I am experiencing something strange. I am working on a script to remote install Splunk on servers via a script. In this script I ssh to my practice servers (5 amazon EC2 instances running Redhat). ...
0
votes
1answer
934 views

Supervisor: no such file or directory even though it is there [duplicate]

I am trying to start supervisor service supervisor start, as root, but it gives me env: /etc/init.d/supervisor: No such file or directory Yet, I can clearly see that file exists: ...
1
vote
2answers
812 views

while read loop

I have a file like one below var 3 2014 string var1 4 2011 string4 var2 6 1999 string2 var3 1 2016 string6 Then i have this while read loop to compare one of the ...
2
votes
2answers
458 views

How do i run a command only after previous command is unsuccessful in bash? [duplicate]

We use && operator to run a command after previous one finishes. update-system-configuration && restart-service but how do I run a command only if previous command is unsuccessful ? ...
3
votes
2answers
147 views

shell script to extract between characters

I would like to extract a user name from the file between the keywords "/" and "NET" like below. How can I do so with programs like awk, sed or cut. from: audit: command=true ...
0
votes
1answer
143 views

predetermine script input text

I have a script that automatically sets up an emailing server based off what I enter for the following echo "Please enter your main domain: (Ex.: website.com)" read DOMINIO if [ $DOMINIO = "" ]; then ...
2
votes
7answers
264 views

Restart firewall from bash file

I need to restart firewall periodically, so I created a bash file to add it to CRON tables. In terminal, I restart firewall using command: service firewall restart but if I have similar line in ...
1
vote
1answer
48 views

How to put “rm -i” in an iteration?

echo "$MOUNTPOINTLIST" | while read onelinefortouch; do touch "${onelinefortouch}testfileforwrite"; done echo "$MOUNTPOINTLIST" | while read onelineforrm; do rm -i "${onelineforrm}testfileforwrite"; ...
-1
votes
1answer
769 views

How create calculator in linux script?

I am trying to create a calculator: echo "What is your number?" read n1 echo "what is your second number?" read n2 echo "what do you want to do?" echo "1. add" echo "2. subtract" echo "3. divide" ...
1
vote
4answers
440 views

Remove all brackets in filename

I've been trying to remove all brackets in my filename(s). Can anyone help me create a bash script to do that? This bash script below work flawlessly for non-bracket filename(s), but if there are any ...
2
votes
2answers
249 views

One-liner to sort and uniq two outputs

I'm currently doing this to sort and uniq the output of two different commands: tshark -r sample.pcap -T fields -e eth.src -e ip.src > hello tshark -r sample.pcap -T fields -e eth.dst -e ip.dst ...
0
votes
1answer
47 views

How to redirect the time a task takes to complete into a log file, given that such task is already redirecting?

I have a shell script running a python task, whose stdout is being redirected to a log file: python script.py >> log.txt I wish to also log the time this task takes to complete, into the same ...
-2
votes
4answers
110 views

How to print last few contents in a line?

I have a file that has lines shown below, ta=/*92/*39/*1/*649/*12 ta=/*92/*12/*4/*342/*90 ta=/*92/*33/*9/*455/*3 ta=/*92/*12/*3/*649/*25 ta=/*92/*99/*7/*649/*7 and so on. I want a file that will ...
1
vote
2answers
1k views

How do I add ASCII art to my Bash?

I see other people doing this, occasionally. They'll add something like the following to the start of their terminal, sort of a welcome screen: ____ _____ _ _ _____ __ __ _ _ __ ...
0
votes
1answer
52 views

Should I move my custom commands from the end of ~/.profile to the end of ~/.zprofile when I install zsh and oh-my-zsh?

I am a new user of zsh and oh-my-zsh. Before I installed zsh and oh-my-zsh I configured my ~/.profile to start some programs automatically. For example, my ~/.profile would start guake after a 4 ...
0
votes
0answers
88 views

CSH: Determine index number of string in an array

I am using csh. Consider an array of arbitrary length: set array = ( abc def ghi ) I have the following variable set var = "def" How can I find $var in $array and determine its index value? I ...