command-line-interface

Is there a way to follow redirects with command line cURL?

大兔子大兔子 提交于 2019-11-27 10:03:12
I know that in a php script: curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); will follow redirects. Is there a way to follow redirects with command line cURL? Use the location header flag: curl -L <URL> user3817445 I had a similar problem. I am posting my solution here because I believe it might help one of the commenters. For me, the obstacle was that the page required a login and then gave me a new URL through javascript. Here is what I had to do: curl -c cookiejar -g -O -J -L -F "j_username=yourusename" -F "j_password=yourpassword" <URL> Note that j_username and j_password is the name of

How to distinguish command-line and web-server invocation? [duplicate]

本小妞迷上赌 提交于 2019-11-27 09:31:52
问题 Is there a way to distinguish if a script was invoked from the command line or by the web server? ( See What is the canonical way to determine commandline vs. http execution of a PHP script? for best answer and more detailed discussion - didn't find that one before posting) I have a (non-production) server with Apache 2.2.10 and PHP 5.2.6. On it, in a web-accessible directory is my PHP script, maintenance_tasks.php . I would like to invoke this script from the command line or through a HTTP

Best way to extract MAC address from ifconfig's output?

霸气de小男生 提交于 2019-11-27 09:28:49
问题 What is the best way to extract the MAC address from ifconfig 's output? Sample output: bash-3.00# ifconfig eth0 eth0 Link encap:Ethernet HWaddr 1F:2E:19:10:3B:52 inet addr:127.0.0.66 Bcast:127.255.255.255 Mask:255.0.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 .... .... Should I use cut, AWK or anything else, and what are the merits and demerits of one method over the other. 回答1: You can do a cat under /sys/class/ cat /sys/class/net/*/address Specifically for eth0 cat /sys/class/net

Attach to a processes output for viewing

笑着哭i 提交于 2019-11-27 08:59:15
问题 How would I 'attach' a console/terminal-view to an applications output so I can see what it may be saying? How would I detach from an applications output without killing the application? Normally if you fire up a talkative application using the command line you get to see all kinds of wonderful output. However, let’s say I have a particularly chatty programming running, like KINO, and I want to view its output at any given moment without restarting it through the command line. I cannot; at

Set max_execution_time in PHP CLI

妖精的绣舞 提交于 2019-11-27 07:24:23
I know that PHP CLI is usually used because of none time limits and primary because it is not using Apache threads/processes. But is there any way how to explicitly set the max_execution_time for some scripts which i don't want to have the freedom of "unlimited time" and just want to keep those script under control? If you think this question may be better answered on superuser.com and have permission to move it, do it. :) Edit : I've been Googling a bit and found the right parameter: php -d max_execution_time=5 script.php Jon The documentation says that when running in command line mode, the

Why does my C# array lose type sign information when cast to object?

笑着哭i 提交于 2019-11-27 06:57:39
Investigating a bug, I discovered it was due to this weirdness in c#: sbyte[] foo = new sbyte[10]; object bar = foo; Console.WriteLine("{0} {1} {2} {3}", foo is sbyte[], foo is byte[], bar is sbyte[], bar is byte[]); The output is "True False True True", while I would have expected " bar is byte[] " to return False. Apparently bar is both a byte[] and an sbyte[] ? The same happens for other signed/unsigned types like Int32[] vs UInt32[] , but not for say Int32[] vs Int64[] . Can anyone explain this behavior? This is in .NET 3.5. UPDATE: I've used this question as the basis for a blog entry,

Git cli in Russian after brew upgrade

≯℡__Kan透↙ 提交于 2019-11-27 06:49:39
问题 My git cli switched to russian after brew upgrade. I've tried to find why, or how, but no clue. $ git --version git version 2.19.0 How do I fix this!? My locale doesn't mention russian at all $ locale LANG= LC_COLLATE="C" LC_CTYPE="UTF-8" LC_MESSAGES="C" LC_MONETARY="C" LC_NUMERIC="C" LC_TIME="C" LC_ALL= 回答1: It happened because of removing "NO_GETTEXT=1" line here: https://github.com/Homebrew/homebrew-core/commit/2049390786eff5dd50862ee63ddca822dc138c64. I think setting LC_* is not an option

call up an EDITOR (vim) from a python script

夙愿已清 提交于 2019-11-27 06:44:13
I want to call up an editor in a python script to solicit input from the user, much like crontab e or git commit does. Here's a snippet from what I have running so far. (In the future, I might use $EDITOR instead of vim so that folks can customize to their liking.) tmp_file = '/tmp/up.'+''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(6)) edit_call = [ "vim",tmp_file] edit = subprocess.Popen(edit_call,stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True ) My problem is that by using Popen, it seems to keep my i/o with the python script from going into the

How do I run Rake tasks within a Ruby script?

余生颓废 提交于 2019-11-27 06:39:59
I have a Rakefile with a Rake task that I would normally call from the command line: rake blog:post Title I'd like to write a Ruby script that calls that Rake task multiple times, but the only solution I see is shelling out using `` (backticks) or system . What's the right way to do this? from timocracy.com : require 'rake' require 'rake/rdoctask' require 'rake/testtask' require 'tasks/rails' def capture_stdout s = StringIO.new oldstdout = $stdout $stdout = s yield s.string ensure $stdout = oldstdout end Rake.application.rake_require '../../lib/tasks/metric_fetcher' results = capture_stdout

Is there a way to make a console application run using only a single file in .NET Core?

爷,独闯天下 提交于 2019-11-27 05:24:26
In .NET framework, you can make a single .EXE file that will run from the command line without having any extra config files (and if using ILMerge, you can put all .DLL references into the 1 .EXE assembly). I am taking a stab at using .NET Core to accomplish the same thing, but so far without success. Even the simplest Hello World application with no dependencies requires there to be a file named <MyApp>.runtimeconfig.json in order to run using dotnet.exe . dotnet F:\temp\MyApp.dll The contents of the <MyApp>.runtimeconfig.json are as follows: { "runtimeOptions": { "framework": { "name":