LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 11-15-2012, 02:47 PM   #1
cfaxon1
LQ Newbie
 
Registered: Jan 2011
Posts: 4

Rep: Reputation: 0
Question running script in background ...


The ./script_name.sh& doesn't work for me.

I also tried it with a space between the script and the &: ./script_name.sh &

This didn't work either. My script calls and closes a GUI repeatedly, which doesn't bother me too much since
it just pops up behind the terminal window, but I would like to be free to move to other directories and continue my
work uninterrupted without opening multiple terminal windows.

Any ideas why this wouldn't be working?
 
Old 11-15-2012, 03:30 PM   #2
cfaxon1
LQ Newbie
 
Registered: Jan 2011
Posts: 4

Original Poster
Rep: Reputation: 0
Hmmm....not working for me

[deleted]
 
Old 11-15-2012, 04:37 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
I split your necro-posts out of the long-dead thread. Can you please
describe in what way the "doesn't work for me" manifests itself?



Cheers,
Tink
 
Old 11-16-2012, 07:39 AM   #4
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Slack14_64_Multilib
Posts: 2,715
Blog Entries: 3

Rep: Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626
post contents of script_name.sh please.

Please use [code][/code] tags.
Thank you,
 
Old 11-16-2012, 12:01 PM   #5
cfaxon1
LQ Newbie
 
Registered: Jan 2011
Posts: 4

Original Poster
Rep: Reputation: 0
Here are the contents of my script

Code:
#!/bin/bash
#
# Run name
RUN=clv1_1000x_11.2.BLoss
# species to loop
SPECIES="CLV1 HCL"
# directory w/ data files
DATA_DIR="./"
# Days to loop
YYYYMMDD="20060531 20060601 20060602 20060603 20060604 20060605
    20060606 20060607 20060608 20060609 20060610 20060611
    20060612 20060613 20060614 20060615 20060616 20060617
    20060618 20060619 20060620 20060621 20060622 20060623
    20060624 20060625 20060626 20060627 20060628 20060629
    20060630 20060701 20060702"
# loop for each species
for sp in $SPECIES; do
# loop for all days in this scenario
  for year in  $YYYYMMDD; do
    FILE=camx5401pr_cb05.$year.dfw8h2.bc06_06jun.reg2.2006ep0ext_eta_5soil_sfcfddats_tkekv200.${RUN}.avrg.grd03
    if [ -f $FILE ]
    then
      MMDD=`echo $year | cut -c 5-8`
      echo "Grabbing $sp Data at EML for $year"
      echo "${FILE} is being processed"
# call pave
      pave \
      -f ${DATA_DIR}/${FILE} \
      -subdomain 24 46 24 46 \
      -s "${sp}a*1000" \
      -save2ascii ./${MMDD}.${sp}.dat \
      -exit
    else
      echo "File $FILE not found..."
    fi
  done
done
#-------------------------Patch all *.dat files together---------------*
# define io species/files for program tscln
#
FIN_TYPE="dat"
FOUT_TYPE="csv"
# define species
SPEC1="HCL"
SPEC2="CLV1"
# define i/o file types corresponding to extracted species
FIN1="*.$SPEC1.$FIN_TYPE"
FOUT1="*$FIN1.$FOUT_TYPE*"
FCOMP1="$SPEC1.$RUN.$FOUT_TYPE"
FIN2="*.$SPEC2.$FIN_TYPE"
FOUT2="*$FIN2.$FOUT_TYPE*"
FCOMP2="$SPEC2.$RUN.$FOUT_TYPE"
# input/out directory and program directories
OUTDIR="/corral/work/cfaxon1/camx/output/dfw8h2.tx.prm/eml_time_series/$RUN/"
HEADER="/corral/work/cfaxon1/data_processing/tscln/header.txt"
PROG="/corral/work/cfaxon1/data_processing/tscln/tscln"
# make sure output directory exists
if [ ! -d $OUTDIR ]
  then
    mkdir $OUTDIR
fi

# Patch all files together
for file in $FIN1; do
  OUT="$OUTDIR/$FCOMP1"
  if [ -f $file ]
  then
    echo Next input file: $file
    echo "$file" | $PROG
  else
    echo Input file $file does not exist.
  fi
done
# Patch all files together
cat $HEADER $FOUT1 > $OUT

for file in $FIN2; do
  OUT="$OUTDIR/$FCOMP2"
  if [ -f $file ]
  then
    echo Next input file: $file
    echo "$file" | $PROG
  else
    echo "Input file $file does not exist."
    echo 'input file does not exist.'
  fi
done
# Patch all files together
cat $HEADER $FOUT2 > $OUT
# Move all .csv files into output directory
mv *.$FOUT_TYPE $OUTDIR
# make subdir for dumped time series
JUNKDIR="./extracted_time_series"
if [ ! -d $JUNKDIR ]
  then
  mkdir $JUNKDIR
fi
mv *.$FIN_TYPE $JUNKDIR
The script dumps time series data from a single grid cell in a gridded output file and then calls a program to
change the format of each and then to combine all the days into one csv file. I'm new to bash and I'm sure there are
some more efficient ways to write the script, so any constructive criticism in that regard would be appreciated.

But what I mean by "not working" is that when I try to run it in the background using the ./[scriptname]& or ./[scriptname] &, everything still runs on the terminal and crowds screen as if I had run it without the &. I had assumed running in the background meant that it would leave the command line free so that I could continue working while it ran. Am I incorrect in my understanding? Thanks in advance for any feedback.
 
Old 11-16-2012, 12:36 PM   #6
superdog
Member
 
Registered: Feb 2008
Distribution: slackware, suse, anything that begins with S
Posts: 45

Rep: Reputation: 16
I think you need to also redirect output. So use something like
Code:
command &>/dev/null
or
Code:
command &>/tmp/output.log
if you want to log any errors. Not sure how good a method this is, just what i do when running noisy gui commands in a terminal

Last edited by superdog; 11-16-2012 at 12:36 PM. Reason: missing redirect operator
 
1 members found this post helpful.
Old 11-19-2012, 11:56 AM   #7
cfaxon1
LQ Newbie
 
Registered: Jan 2011
Posts: 4

Original Poster
Rep: Reputation: 0
Cool

Thanks for the tip superdog. That seemed to work, except that I had to write it like:

Code:
command > ./log.txt &
with the & at the end. I was misunderstanding that the output would be redirected by running it in the background,
but it makes sense that you have to indicate where it should be redirected.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem running a program/script in the background from a script newbie01.linux Programming 5 03-28-2011 07:28 AM
Running script in background? bobbyright Linux - Newbie 4 03-02-2010 02:17 AM
Running script in background bob81 Linux - Newbie 1 03-04-2009 12:11 AM
logging script, running background how lhrt Linux - General 2 06-09-2006 10:06 AM
Running script in background skguha Linux - Newbie 7 04-02-2004 08:32 AM


All times are GMT -5. The time now is 08:33 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration