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

learn more… | top users | synonyms (2)

1
vote
1answer
201 views

How to kill inactive user logins on Solaris?

On a Solaris 10 server if i do a w, I get this: 12:26pm up 85 day(s), 1:13, 6 users, load average: 0.38, 0.36, 0.38 User tty login@ idle JCPU PCPU what blah pts/1 ...
0
votes
1answer
342 views

could not change directory to “/home/corey/scripts”: Permission denied

I get the error message... could not change directory to "/home/corey/scripts": Permission denied ... when I run the following script ... #!/bin/bash sudo -u postgres psql < setup_dev_db.sql ...
8
votes
3answers
626 views

How would I use GNU Parallel for this while loop?

So I have a while loop: cat live_hosts | while read host; do sortstuff.sh -a "$host" > sortedstuff-"$host"; done But this can take a long time. How would I use GNU Parallel for this while loop?
-2
votes
1answer
1k views

script to check cpu utilization in linux

I want a bash script that show the CPU consumption every minute and save it in a file. The output would be like this: 11/09/2015 10:00: CPU: 60% 11/09/2015 10:01: CPU: 72% 11/09/2015 10:02: CPU: 32% ...
0
votes
2answers
252 views

How to catch carriage return / line feed in case statement

I tried the following to no avail and couldn't find any documentation. read Option case $Option in [1] ) echo "1" ;; [2] ) echo "2" ;; [$'\n'] ) echo "LF" ;; [0] ) exit ;; * ) ...
0
votes
1answer
120 views

Finding Writer of a file [duplicate]

suppose, I want to search for a text in some papers in pdf format and whenever I will find the text in any of those files, I want to print the title and writer's name of the paper.Normally We can ...
2
votes
4answers
127 views

How to add hyphens at the first empty line of a text file?

I'm trying to add three hyphens to the first empty line of a given text file, and am trying to use sed for this. My initial file (a MultiMarkdown file) looks something like this: title: "Ch. 1: ...
1
vote
2answers
912 views

How do I pass a variable into sftp?

I'm trying to match a filename to a string, which is basically a timestamp, during an SFTP connection. How do I match part of the filename? I can't seem to declare a variable within an SFTP ...
0
votes
1answer
93 views

Scanning a pdf file [duplicate]

I want to scan a research paper of pdf format using linux shell command. If I want to print/display only the name of the authors and the title of the paper, is there any specific way to do that?
1
vote
2answers
38 views

Reading a variable-sized line and splitting its content into separate lines with text

I have a file with the header (first line) with a variable length; and it comes as: "One"|"Two"|"Three" or "One"|"Two"|"Three"|...|"One Hundred" and want to get do a loop that transforms it ...
5
votes
1answer
575 views

message to the user after the first login

is there any way to display a message to the user just after the first login? I want to show him that "this is the first time that you are logging with this account".
0
votes
1answer
66 views

Searching a keyword in a pdf file [duplicate]

I want to search for a specific keyword in a pdf file using linux shell. How I will use the grep command to do that?
1
vote
1answer
17 views

Bash Script - initiate remote X redirected application

Perhaps I am using the wrong keywords to find an answer to this requirement. I have a GUI installed on a remote linux system that use remote connecting into it and initiating the application with X ...
0
votes
0answers
68 views

Is the pipe overloaded?

I am using a coprocess to run commands in siebel server manager. I am reading commands from a text file (around 2000 commands) and executing them one by one in siebel server manager. After executing ...
0
votes
2answers
167 views

How to ssh into a remote box, run a command and keep it running after I disconnect [duplicate]

I've seen people saying use screen. But when I typed "screen" in the terminal, I got: "Please set a terminal type." Any idea how I can fix this?
-1
votes
2answers
46 views

How to run a task that changes folders by itself

I'd like to run VCS (Video Contact Sheet), a program that creates contact sheets (thumbnails) of video files. This is the scenario: I have a root folder called Temp. Inside, I have many other folders ...
4
votes
5answers
2k views

Bash: Parse multi-line into single-line commands

I have to write a Bash script which checks if another Bash script contains a certain command line. Since Bash allows you to split a command line over multiple lines, my script must be able to merge ...
0
votes
4answers
243 views

How to delete the newline before EOF in a text/csv file via bash

Below is an example of the data I'm receiving in txt or csv file (seen in EmEditor): However, the final blank line is causing problems when uploading this data into my software. I need to have the ...
2
votes
1answer
108 views

udev power_supply rules not triggering

I know this seems to be the most commonly asked question about udev on here, but I believe I've done everything correctly and yet my rules still never get triggered. The script is executable and works ...
0
votes
1answer
126 views

Convert a Column oriented file to CSV output using shell script

I have a file that come from map reduce output for the format below that needs conversion to CSV using shell script . The dynamic values are five values and they are the transaction IDs and the four ...
1
vote
1answer
120 views

Perl script is running fine in interactive shell but not as a cron job

I have installed dirvish for some backups. I have initialized one vault (host). And now I am using the following script to run it: #!/bin/sh /sbin/dirvish-expire --quiet && /sbin/dirvish-...
-1
votes
3answers
161 views

find most frequently occurring letter/character combinations in a file

find most frequently occurring letter/character combinations in a file Instead of just looking for recurring words (a la: find n most frequent words in a file), I need to list all recurring letter ...
0
votes
2answers
55 views

killing all the processes related to a script

I have a script that calls a lot of programs sequentially. How could I terminate this script once and for all? I know that I could click Ctrl+C to cancel some of the process but killing the whole ...
0
votes
1answer
43 views

I'm trying to write a script to compare results from a code to my already established results for regression testing

I've been trying to write a bash script to run my code, then compare the final output to a previous run (with the correct result) under regression.dat. The goal is for it to tell me if the code ...
3
votes
6answers
96 views

checking the largest number of a specific folder

Inside one of my folder I have a lot of files looks like enum-* $ ls PRIM enum-00020 enum-00040 enum-00059 enum-00078 enum-00101 enum-00122 enum-00141 enum-00160 enum-00179 ...
1
vote
5answers
294 views

Avoid running the script if a variable is not defined

I have a script looks like: c=0 for f in */*; do cp -v "$f" "/myhome/CE$(printf '%0*d' 2 $BATCHNUM)-new-stuctures_extracted/test-$(printf '%0*d' 5 $c)" c=$((c=c+1)) done However, the user must ...
4
votes
1answer
123 views

Thousand separator in awk

I would like to print thousand separator with awk's printf. In bash, it is pretty straightforward: > printf "a %'d b \n" 1234567 a 1,234,567 b > LC_NUMERIC=fr_FR.utf8 > printf "a %'d b \n" ...
0
votes
1answer
257 views

PM2 inside bash script deployed by puppet not working

#!/bin/bash # install needed RPMS yum -y install gcc-c++ git # downlaod and compile node wget https://nodejs.org/dist/v0.12.7/node-v0.12.7.tar.gz tar -xvzf node-v0.12.7.tar.gz cd node-v0.12.7 ./...
1
vote
2answers
79 views

Select file based on number of lines and manipulate the result

I have a large number of files, all with the same format. line 1: Gene ID line 2: chromosomal position line 3 - x: names of genetic variants) I want to select only files containing at least 5 ...
18
votes
2answers
2k views

Is there something like JavaScript's “split()” in the shell?

It's very easy to use split() in JavaScript to break a string into an array. What about shell script? Say I want to do this: $ script.sh var1_var2_var3 When the user give such string ...
0
votes
2answers
62 views

Why this break can't get me out of this while-do loop?

code: This is for creating some animation and when the count variable $i gets 5, it stops and carry on the future shell code. chars="/-\|" while :; do for (( i=0; i<${#chars}; i++ )); do ...
0
votes
1answer
165 views

Raspberry Pi run script after startup

I have a Raspberry Pi with openvpn installed and running perfect and I want to launch a command after the desktop mode enters and after all is loaded and running including openvpn on Raspbian. I ...
0
votes
1answer
59 views

I want to delete from particular words in all the line if that particular word is present

eg: CREATE VIEW AIPKEYITEM.SEASONGROUPNETSALES ( CALENDARID , PRODUCTGROUPID FOR COLUMN PRDGRPID , NETSALESDOLLARS FOR COLUMN NETSA00001 , NETSALESUNITS FOR COLUMN NETSA00002 ) AS SELECT ...
0
votes
1answer
113 views

Difference between two dates on Linux

I'm getting a date in the format of v_date=$(date +"%Y%m%d" -d "1970-01-01 + $(stat -c '%Z' file ) secs") v_sysdate=$(date +%Y%m%d) echo "$v_date" 20150907 echo "$v_sysdate" 20150907 ...
2
votes
2answers
24 views

Sub Shell Redirection Error With Variable ( while … ) $3 > $testdir/$testfile.log

My scripts executes the sub shell command along the lines of: ( while ..... ) $3>$testdir/$testfile.log I get the error: line 75: syntax error near unexpected token `$3' line 75: ` ) $3>$...
3
votes
2answers
337 views

Move a file and replace it by a symlink

Can someone give me a command that would: move a file towards a new directory and leave a symlink in its old location towards its new one
2
votes
1answer
105 views

echo the created directory name

I'm trying to echo the new directory that I'm creating in the script. BACKUP_DIR=`mkdir /tmp/"$TICKET_NUM"_EAR_BACKUP_"$(date "+%Y%m%d")"` echo $BACKUP_DIR But, the newly created directory is not ...
2
votes
1answer
228 views

System event on AC adapter insert or battery unplugged?

Does Ubuntu 15.04 (or maybe just Linux in general) have any sort of measurable event that fires when a laptop's AC power is disconnected and the unit flips over to battery power? I would like to ...
1
vote
2answers
112 views

List files in hierarchy of directory

I need to list files in hierarchy of directory. For that I wrote script like foreach file ( * ) ls ${file}/*/*/*/*/*.root > ${file}.txt end But for this I have to know that in the directory $...
1
vote
2answers
48 views

Is there a command line spell to save specific columns by name in a CSV-file?

Suppose I have a crazy data set in CSV: SOS_VOTERID,COUNTY_NUMBER,COUNTY_ID,LAST_NAME,FIRST_NAME,MIDDLE_NAME,SUFFIX,DATE_OF_BIRTH,REGISTRATION_DATE,PARTY_AFFILIATION,RESIDENTIAL_ADDRESS1,...
1
vote
2answers
128 views

Finding difference in dates which is in format “%Y%m%d%H%M%S”

I have a two dates in date +"%Y%m%d%H%M%S" format. How to find the difference and how to check whether the difference is more than 4 hours? This is how i have tried echo $(( ( $(date +"%Y%m%d%H%M%S")...
0
votes
1answer
44 views

finding time of the file received in a directory on reading a filename [duplicate]

I read a file which have all the file names line by line which ($var) returns the file names in the directory /home/mydir . input="/home/mydir/test/myfile" while IFS= read -r var do /home/mydir/"$var"...
0
votes
1answer
230 views

RRDtool update not working when integers and floats are mixed

I'm trying to store ADSL stats for my router. I didn't do rrdtool info on the others beccause they are now showing the correct value after using the same command as in the script to update. The weird ...
2
votes
1answer
113 views

How can script execute itself via some exec again?

I'm making script for backing up data from server, it's gonna use ssh and scp many times. My private key is password-protected, but I'm using environment without any ssh agent. I'd like to put ...
1
vote
1answer
64 views

Storing integer values from string in rrd

I want to collect stats from my DSL modem every 10 minutes. According to lots of websites it's best to use rrd for this. My modem(TD-W8968) struggles with SNMP so I've made an expect script to pull ...
1
vote
2answers
54 views

Finding a file in a directory based on time

I have a directory called /home/mydir/test A file will be sent from some other team which lands in this directory. How to find the file is whether in that directory for more than 4 hours. I tried ...
0
votes
1answer
153 views

Sudo Apache, with command line ? (not visudo)

I have visudo-edited /etc/sudoers this way: User_Alias APACHE = www-data Cmnd_Alias FIREWALL = /sbin/iptables, /sbin/ifconfig, /sbin/route APACHE ALL = (ALL) NOPASSWD: FIREWALL (To allow php ...
0
votes
2answers
38 views

link cut, find length and cut the new text with the first text's length

I'm stuck up with the below situation. there are two files - sample.war & sample1.48.war now, I've to cut only the first field of the first file. i.e., 'sample'. Next, I've to count the total ...
0
votes
3answers
290 views

Shell Script to change locale has no effect

I wrote a simple script to switch my locale. If I write each line in the console and execute it, it works without any problem or if I put it in .bashrc. However when I execute the script either with ...
-1
votes
3answers
134 views

Find the time of the file received in a particular directory

I have a directory called /home/mydir/test A file will be sent from some other team which lands in this directory. How to find what is the time the file came to this particular directory? ( I need ...