csh 脚本中出现奇怪的非法变量名错误

csh 脚本中出现奇怪的非法变量名错误

我的 csh 脚本出现了一个特殊问题,该问题仅出现在我的 Lenovo Z500 笔记本电脑中。我在其他 3 台具有类似操作系统(Kubuntu 14.04 x64)的计算机上运行了该脚本,唯一遇到此错误的系统就是我的系统。该脚本已编写为自动执行下载过程。我陷入了困境。请帮忙!

我用来运行脚本的命令:xargs -I ds ./exportfile.csh ds [email protected] <pt

csh 脚本:

#! /bin/csh -f
#
# Updated 27 July 2015 to deal with changes for more compact json output format.
#         also added tests for wget failures
# updated 20 March 2015 to deal with new need to not urlescape to words on left of '='
#
# Simple script to fetch a JSOC recordset using calls to wget
#
# call with a two arguments containing a recordset query and your registered email address
# resulting data files are placed into the current directory
#
# see http://jsoc.stanford.edu/jsocwiki/AjaxConnect for further information
#
# e.g.
#   exportfile.csh 'hmi.M_45s[$]' [email protected]
# will get you the most recent SDO/HMI line-of-sight magnetogram if you replace the [email protected] with your
# registered email address (see below)

set noglob

if ($#argv != 2) then
  Two args required, recset and notify
  call=$argv
  exit
endif

# get desired recordset and encode for transmitting
# you can get the following url_escape script at http://jsoc.stanford.edu/ajax/

set ds=`./url_escape.pl "$1"`

# You MUST now include a valid registered email address.  You can use a prior exportdata "notify" email address
# or just make one via http://jsoc2.stanford.edu/ajax/register_email.html
# Change the '$2' in the line below to your notify address if you want the script to not need a second argument.

set notify = `./url_escape.pl "$2"`

# for FITS without full headers use fastest method use the next 2 lines:

# set method=url_quick
# set protocol=as-is

# if, as is most common, you want full FITS headers or
# if you want to specify the filename format for the returned data or if you expect multiple
# files you should use the next two lines.

set method=url
set protocol="FITS"

# to specify filename formats add the "filenamefmt" command to the cmd line below.
# you will need to url_escape the filenamefmt. 

set ffmt = `./url_escape.pl 'hmi.sharp_cea_720s.{HARPNUM}.{T_REC:A}.{segment}'`

set op=exp_request

set cmd = "op=$op&ds=$ds&process=n=0|no_op&method=$method&format=txt&protocol=$protocol&filenamefmt=$ffmt&notify=$notify&requestor=none&sizeratio=1"

set JSOC="http://jsoc.stanford.edu"
set FETCH="$JSOC/cgi-bin/ajax/jsoc_fetch"

# Make a place to put the handshake information
set RESP = /tmp/jsoc_export.$$

wget -S -nv -O $RESP  $FETCH?"$cmd"
if ($?) then
  wget failed, response was: $RESP
  exit
endif

if ($method == "url") then
  set Status = "`grep status $RESP | sed -e 's/[{}]//g' -e 's/: / = /' -e 's/"status"/Status/' -e 's/,.*//'`"
  set $Status
  if ($Status == 4) then
    echo "Export request failed, status=" $Status
    cat $RESP
    echo "Command was " $cmd
    exit
  else if ($Status == 6) then
    echo "Problem with finding registered email address."
    cat $RESP
    exit
  endif

  set requestid = `grep requestid $RESP`
  if ($#requestid == 0) then
    echo no requestid found
    exit
  endif
  set $requestid

  # wait for processing to complete, do status query with sleeps and initial sleep
  set qry = "op=exp_status&requestid=$requestid&format=txt"
  while (1)
    sleep 3
    wget  -S -O $RESP $FETCH?"$qry"
    if ($?) then
      wget failed, response was: $RESP
      exit
    endif
    set Status = "`grep status $RESP | sed -e 's/[{}]//g' -e 's/: / = /' -e 's/"status"/Status/' -e 's/,.*//'`"
    set $Status
    if ($Status == 0) break
    if ($Status == 6) then
        continue
    else if ($Status > 2) then
        echo Error in processing export request
        echo possibly bad recordset format or no data in SUMS
        cat $RESP
        exit
    endif
  end

else if ($method == "url_quick") then
  set Status = "`grep status $RESP | sed -e 's/[{}]//g' -e 's/: / = /' -e 's/"status"/Status/' -e 's/,.*//'`"
  set $Status
  if ($Status == 4) then
    echo "Export request failed, status=" $Status
    cat $RESP
    echo "Command was " $cmd
    exit
  else if ($Status == 6) then
    echo "Problem with finding registered email address."
    cat $RESP
    exit
  endif
endif

set dir = `grep dir $RESP`
set $dir
set count = `grep count $RESP`
set $count

# Now $RESP contains headers used above and table of count files.
# loop through files and fetch them.

while ($count > 0)
  set REC = `tail --lines=$count $RESP | head -1`
  set QUERY = $REC[1]
  set FILE = $REC[2]
  set URL = $JSOC$dir/$FILE
  echo Fetching $QUERY as `basename $FILE`
  wget -S -nv $URL
  if ($?) then
    wget failed, response was: $RESP
    exit
  endif
  @ count = $count - 1
  end

# remove working file.  Parhaps useful to save with the data.
# rm $RESP
mv $RESP ./


# The cgi-bin programs that you can use with wget or curl or such programs include
#   jsoc_fetch
#   jsoc_info
#   show_series
#   show_info
#
#   If you need to pass flags (e.g. -X) to these programs, use 'X=1' on the urlencoded command line.
#   To see the full set of options see the man pages in doxygen from the jsoc2 home page.
#
# If you want to run exportfile.csh to fetch a group of recordsets you can place them
# into a file, one line per recordset, with surrounding single quotes, and no internal spaces.
# then use xargs to bring the set of recordsets, one at a time.

url_scape.pl:

#!/usr/bin/perl
use CGI; print CGI::escape($ARGV[0]); print "\n";

pt.txt:

'hmi.sharp_cea_720s[][2010.02.05_18:47_TAI-2010.02.05_18:59_TAI][? NOAA_ARS ~ "11045" ?]{Bp,Br,Bt}'
'hmi.sharp_cea_720s[][2010.02.06_02:20_TAI-2010.02.06_02:32_TAI][? NOAA_ARS ~ "11045" ?]{Bp,Br,Bt}'
'hmi.sharp_cea_720s[][2010.02.07_21:01_TAI-2010.02.07_21:13_TAI][? NOAA_ARS ~ "11045" ?]{Bp,Br,Bt}'
'hmi.sharp_cea_720s[][2010.02.11_11:19_TAI-2010.02.11_11:31_TAI][? NOAA_ARS ~ "11046" ?]{Bp,Br,Bt}'

Konsole 输出:

afshinrk-Lenovo-IdeaPad-Z500:~/export> xargs -I DS ./exportfile.csh DS [email protected] < pt
xargs -I DS ./exportfile.csh DS [email protected]
  HTTP/1.1 200 OK
  Date: Tue, 09 Feb 2016 13:50:09 GMT
  Server: Apache/2.2.3 (CentOS)
  Connection: close
  Transfer-Encoding: chunked
  Content-Type: text/plain
2016-02-09 17:20:10 URL:http://jsoc.stanford.edu/cgi-bin/ajax/jsoc_fetch?op=exp_request&ds=hmi.sharp_cea_720s%5B%5D%5B2012.07.05_10%3A24_TAI-2012.07.05_10%3A36_TAI%5D%5B%3F%20NOAA_ARS%20~%20%2211515%22%20%3F%5D%7BBp%2CBr%2CBt%7D&process=n=0%7Cno_op&method=url&format=txt&protocol=FITS&filenamefmt=hmi.sharp_cea_720s.%7BHARPNUM%7D.%7BT_REC%3AA%7D.%7Bsegment%7D&notify=afo_rk%40yahoo.com&requestor=none&sizeratio=1 [127] -> "/tmp/jsoc_export.2786" [1]
Illegal variable name.
  HTTP/1.1 200 OK
  Date: Tue, 09 Feb 2016 13:50:12 GMT
  Server: Apache/2.2.3 (CentOS)
  Connection: close
  Transfer-Encoding: chunked
  Content-Type: text/plain
2016-02-09 17:20:12 URL:http://jsoc.stanford.edu/cgi-bin/ajax/jsoc_fetch?op=exp_request&ds=hmi.sharp_cea_720s%5B%5D%5B2012.07.05_13%3A26_TAI-2012.07.05_13%3A38_TAI%5D%5B%3F%20NOAA_ARS%20~%20%2211513%22%20%3F%5D%7BBp%2CBr%2CBt%7D&process=n=0%7Cno_op&method=url&format=txt&protocol=FITS&filenamefmt=hmi.sharp_cea_720s.%7BHARPNUM%7D.%7BT_REC%3AA%7D.%7Bsegment%7D&notify=afo_rk%40yahoo.com&requestor=none&sizeratio=1 [127] -> "/tmp/jsoc_export.2791" [1]
Illegal variable name.
  HTTP/1.1 200 OK
  Date: Tue, 09 Feb 2016 13:50:14 GMT
  Server: Apache/2.2.3 (CentOS)
  Connection: close
  Transfer-Encoding: chunked
  Content-Type: text/plain
2016-02-09 17:20:16 URL:http://jsoc.stanford.edu/cgi-bin/ajax/jsoc_fetch?op=exp_request&ds=hmi.sharp_cea_720s%5B%5D%5B2012.07.05_18%3A48_TAI-2012.07.05_19%3A00_TAI%5D%5B%3F%20NOAA_ARS%20~%20%2211515%22%20%3F%5D%7BBp%2CBr%2CBt%7D&process=n=0%7Cno_op&method=url&format=txt&protocol=FITS&filenamefmt=hmi.sharp_cea_720s.%7BHARPNUM%7D.%7BT_REC%3AA%7D.%7Bsegment%7D&notify=afo_rk%40yahoo.com&requestor=none&sizeratio=1 [127] -> "/tmp/jsoc_export.2796" [1]
Illegal variable name.
  HTTP/1.1 200 OK
  Date: Tue, 09 Feb 2016 13:50:18 GMT
  Server: Apache/2.2.3 (CentOS)
  Connection: close
  Transfer-Encoding: chunked
  Content-Type: text/plain
2016-02-09 17:20:19 URL:http://jsoc.stanford.edu/cgi-bin/ajax/jsoc_fetch?op=exp_request&ds=hmi.sharp_cea_720s%5B%5D%5B2012.07.06_03%3A10_TAI-2012.07.06_03%3A22_TAI%5D%5B%3F%20NOAA_ARS%20~%20%2211515%22%20%3F%5D%7BBp%2CBr%2CBt%7D&process=n=0%7Cno_op&method=url&format=txt&protocol=FITS&filenamefmt=hmi.sharp_cea_720s.%7BHARPNUM%7D.%7BT_REC%3AA%7D.%7Bsegment%7D&notify=afo_rk%40yahoo.com&requestor=none&sizeratio=1 [127] -> "/tmp/jsoc_export.2801" [1]
Illegal variable name.
  HTTP/1.1 200 OK
  Date: Tue, 09 Feb 2016 13:50:20 GMT
  Server: Apache/2.2.3 (CentOS)
  Connection: close
  Transfer-Encoding: chunked
  Content-Type: text/plain
2016-02-09 17:20:21 URL:http://jsoc.stanford.edu/cgi-bin/ajax/jsoc_fetch?op=exp_request&ds=hmi.sharp_cea_720s%5B%5D%5B2012.07.06_10%3A57_TAI-2012.07.06_11%3A09_TAI%5D%5B%3F%20NOAA_ARS%20~%20%2211515%22%20%3F%5D%7BBp%2CBr%2CBt%7D&process=n=0%7Cno_op&method=url&format=txt&protocol=FITS&filenamefmt=hmi.sharp_cea_720s.%7BHARPNUM%7D.%7BT_REC%3AA%7D.%7Bsegment%7D&notify=afo_rk%40yahoo.com&requestor=none&sizeratio=1 [127] -> "/tmp/jsoc_export.2806" [1]
Illegal variable name.

答案1

我运行了脚本,-v结果发现问题出在变量上$?

相关内容