|
| 1 | +#! /bin/csh -f |
| 2 | +# |
| 3 | +# c-shell script to download selected files from rda.ucar.edu using Wget |
| 4 | +# NOTE: if you want to run under a different shell, make sure you change |
| 5 | +# the 'set' commands according to your shell's syntax |
| 6 | +# after you save the file, don't forget to make it executable |
| 7 | +# i.e. - "chmod 755 <name_of_script>" |
| 8 | +# |
| 9 | +# Experienced Wget Users: add additional command-line flags here |
| 10 | +# Use the -r (--recursive) option with care |
| 11 | +# Do NOT use the -b (--background) option - simultaneous file downloads |
| 12 | +# can cause your data access to be blocked |
| 13 | +set opts = "-N" |
| 14 | +# |
| 15 | +# Replace "xxxxxx" with your password |
| 16 | +# IMPORTANT NOTE: If your password uses a special character that has special |
| 17 | +# meaning to csh, you should escape it with a backslash |
| 18 | +# Example: set passwd = "my\!password" |
| 19 | +# |
| 20 | +# Copyright (C) 2015 Bekaert David - University of Leeds |
| 21 | +# Email: eedpsb@leeds.ac.uk or davidbekaert.com |
| 22 | +# script generated from UCAR webpage |
| 23 | +# |
| 24 | +# This program is free software; you can redistribute it and/or modify |
| 25 | +# it under the terms of the GNU General Public License as published by |
| 26 | +# the Free Software Foundation; either version 2 of the License, or |
| 27 | +# (at your option) any later version. |
| 28 | +# |
| 29 | +# This program is distributed in the hope that it will be useful, |
| 30 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 31 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 32 | +# GNU General Public License for more details. |
| 33 | +# |
| 34 | +# You should have received a copy of the GNU General Public License along |
| 35 | +# with this program; if not, write to the Free Software Foundation, Inc., |
| 36 | +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 37 | +# |
| 38 | + |
| 39 | + |
| 40 | +if ($#argv != 3) then # DB |
| 41 | + echo "get_GFS.csh passwd email filelist" |
| 42 | +endif |
| 43 | + |
| 44 | +set passwd = $argv[1] |
| 45 | +set email = $argv[2] |
| 46 | +set filelist = $argv[3] |
| 47 | + |
| 48 | + |
| 49 | +set num_chars = `echo "$passwd" |awk '{print length($0)}'` |
| 50 | +if ($num_chars == 0) then |
| 51 | + echo "You need to set your password before you can continue" |
| 52 | + echo " see the documentation in the script" |
| 53 | + exit |
| 54 | +endif |
| 55 | +@ num = 1 |
| 56 | +set newpass = "" |
| 57 | +while ($num <= $num_chars) |
| 58 | + set c = `echo "$passwd" |cut -b{$num}-{$num}` |
| 59 | + if ("$c" == "&") then |
| 60 | + set c = "%26"; |
| 61 | + else |
| 62 | + if ("$c" == "?") then |
| 63 | + set c = "%3F" |
| 64 | + else |
| 65 | + if ("$c" == "=") then |
| 66 | + set c = "%3D" |
| 67 | + endif |
| 68 | + endif |
| 69 | + endif |
| 70 | + set newpass = "$newpass$c" |
| 71 | + @ num ++ |
| 72 | +end |
| 73 | +set passwd = "$newpass" |
| 74 | +# |
| 75 | +set cert_opt = "" |
| 76 | +# If you get a certificate verification error (version 1.10 or higher), |
| 77 | +# uncomment the following line: |
| 78 | +#set cert_opt = "--no-check-certificate" |
| 79 | +# |
| 80 | +# authenticate - NOTE: You should only execute this command ONE TIME. |
| 81 | +# Executing this command for every data file you download may cause |
| 82 | +# your download privileges to be suspended. |
| 83 | +if ("$passwd" == "xxxxxx") then |
| 84 | + echo "You need to set your password before you can continue" |
| 85 | + echo " see the documentation in the script" |
| 86 | + exit |
| 87 | +endif |
| 88 | +wget $cert_opt -O /dev/null --save-cookies auth.rda.ucar.edu --post-data="email=$email&passwd=$passwd&action=login" https://rda.ucar.edu/cgi-bin/login |
| 89 | +# |
| 90 | +# download the file(s) |
| 91 | +foreach file(`cat $filelist`) |
| 92 | + echo $file |
| 93 | + wget $cert_opt $opts --load-cookies auth.rda.ucar.edu http://rda.ucar.edu/data/ds335.0/GFS0p5/$file |
| 94 | +end |
| 95 | + |
| 96 | +# |
| 97 | +# clean up |
| 98 | +rm auth.rda.ucar.edu |
| 99 | + |
| 100 | + |
0 commit comments