Top tag
Next privilege 1,000 Rep.
See votes, expandable usercard
2 6
 Nice Answer
~58k people reached

  • 0 posts edited
  • 0 helpful flags
  • 5 votes cast
comment How to restart the Python script automatically if it is killed or dies
If you use a cron job then you'll want to either implement or find some code for robust PID file handling. You want to have your service/script/daemon create a PID file (conventionally located under /var/run) and have its start-up code check if the file contents are stale (left by a killed process). This sort of code is surprisingly difficult to write free of races and corner cases.…
comment On executable files in Linux
UNIX scans the first block of the file for certain patterns ("magic numbers") which affect how the file is executed. This varies. #! is interpreted by kernel as a magic number. Linux also supports old COFF/a.out and ELF binary formats, for example. Failing all that (plain text with not #! "comment" ... the shell may attempt to process the text as a script (as csh does, for example). Also Linux supports registration of magic numbers for things like Java .class files with custom interpreters) --- though this is rather obscure (Google: binfmt_misc).
comment On executable files in Linux
Actually there are some other more subtle differences. In MS-DOS and MS Windows batch files are limited to ending in the .BAT extension (and I they added .CMD for NT and later). The 4DOS alternative to COMMAND.COM (and its ilk, including the Norton Utilities derivative) also accepted the .BTM extension. Other than that one could create associations between extensions and executables (including script interpreters) ... but this still isn't much like simply having an executable bit in thee file's mode.
comment On executable files in Linux
The original MS-DOS filesystems only support a handful of "attributes" -- System, Hidden, Volume Label(!), Archive, and Read-only (if I remember correctly). I think there may have been some "reserved bits" which were never used. (Yes, they had a bit on every directory on the system to indicate that this entry was NOT the volume label; it really was that stupid). System was sort of like "hidden+read-only" but different. It was an ill-conceived mess. The "volume bit" was used later, in VFAT, to implement long name support.
comment What's a convenient way of checking what's being added to a log file in realtime?
tail -f | grep ... | while read line; do ...; done is an extremely common scripting idiom among sysadmins. (Yes variants of of it using popen() styled subprocesses count as using the same idiom). It's used to selectively process logged events in near real-time (for example to send alerts or initiated automated remediation scripts).
comment testing services/open ports with telnet?
You cannot use telnet over "any TCP port." You can use it over any TCP connectin where the other side accepts text in its protocol handling. (However it is true that many traditional protocols are text based and thus allow the use of telnet for debugging and similar purposes).
comment Is it possible to stop a shutdown command?
@Ken: shutdown -c and [Ctrl]+[c] are entirely different. shutdown -c is a command which cancels a previously scheduled shutdown (even "now" is scheduled in this sense --- but whether the cancellation will prevent the reboot is a bit of a race in that case). [Ctrl]+[c] will cause you terminal to generate a SIGINT (interrupt signal) to whichever process was currently attached to it. This might work on a running shutdown command but that's rather incidental to your question.
comment How can I pause/resume rsync
Also note that Ctrl-Z to suspend a process is likely, after some time, to result in the timeout of any TCP network connections which were established by that program. Thus leaving an rsync suspended for more than a few minutes will very likely cause it to quit abruptly with an error message when you put it back in the foreground and it finds that its opened sockets are returning errors from reads and writes.
comment Scheduling commands by system inactivity
Keep in mind that uptime reports load averages for three different intervals (last minute, last five minutes and last fifteen minutes). In general load average is only the average number of items in the run queue during that time interval. On some systems (Linux in particular) processes in "D" state are counted as runnable. So a system with processes waiting on a slow (or missing) NFS server can appear to have a large load average that has nothing to do with real load on the system.