do shell script "curl etc" not working properly.

I have a script that goes in to my telephone switch and using curl, extracts the log of the calls that happened that week.


Normally this is done by login in via Safari and clicking a button to extract the file to the download folder. When done that way the file works (it is compressed) and the extracted file can be read. The file downloaded is named gespr_dat.csv.g, the file you extract from it is gespr_dat.csv that can than be opened by several applications.


When done via curl the file downloaded is gespr_dat.csv.gz, the file extracted from it becoms gespr_dat.csv.gz.cpgz, and can not be opened but keeps looping when trying to open.



FYI my full script is: do shell script "curl http://192.168.1.190/data_tmp/gespr_dat.csv.gz -s -o /Users/me/Desktop/gespr_dat.csv.gz"


Anybody any idea?

MBP, MM, MBP - 10.6 + Windooz XP on a hard partition

Posted on Oct 10, 2012 2:36 AM

Reply
80 replies

Nov 1, 2012 3:56 AM in response to ChangeAgent

I wish these forums had a better "code" box. Sometimes all this copying-and-pasting can create annoying little errors.


The line right before the error highlighted in red: the space between "-o $outputfile" and the URL is missing.





For testing, you should put it all in a file, and run it using "sh /pathto/that_file". All I did was change the paths, and we already know the script works in principle. Ergo, if it fails now, it's almost certainly due to a typo (missing space etc), or my using a wrong path – which I'm 99.9% sure I didn't do. So if you put it all in a file, and it works when the script is executed as a file, then we know that it should work as well via cron.


I am nearly certain that the only thing which has prevented us from closing this thread is an incomplete $PATH variable in the environment in which cron runs the script, and that using absolute paths in every instance (crontab level and script level) will resolve the issue.




(Hey, does your working script have the "#!/bin/sh" statement at the beginning? I noticed it's not in what we copied-and-pasted. It's probably not necessary, but it wouldn't hurt to include it any and every time shell commands are put in a text file – i.e. a script.)

Nov 1, 2012 4:20 AM in response to marshaul

To elaborate: at this point, we're not really testing that the sequence of commands works; we basically know that it does.


All we're testing at this point is that the structure of the commands is syntactically correct (which in the previous instance it wasn't: the missing space).


At this point:


Step 1: Put the script, with my most recent modifications (the absolute paths), in a file, and make sure that it works completely when executed using "sh /pathto/that_file"


Step 2: Automate that script via cron using


* * * * * /bin/sh /pathto/that_file



I really think that's all it will take to end this thread.

Nov 1, 2012 4:50 AM in response to ChangeAgent

Well, it was worth a try.


(One last time, to be certain: you are not using "open" or "/usr/bin/open" anywhere, correct?)


Very odd. Very annoying.


If you wouldn't mind, there's one more thing I want to check:


Type "mail" in the command line. Do you see a whole bunch of messages?


If so, open one up: just type its number, followed by return. Pick the largest number for the latest message. Pick one that has "Cron" in the subject line, if they all don't.


Post it here (go ahead and leave out everything up to the Subject line, i.e. the personal info).


Thanks.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

do shell script "curl etc" not working properly.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.