The Official *nix Thread

Inane baanter or words of wisdom - you decide...
Post Reply
User avatar
wanye
Baaaaaa!
Baaaaaa!
Posts: 3047
Joined: Tue Sep 07, 2004 12:46 pm 0
PSN: wanye_m
Location: nottingham
Contact:

Re: The Official *nix Thread

Post by wanye »

anyone got any experience of using rsync/scp with ubuntu in cron?

basically, the rsync (or scp) command in the script works when you run it from the commandline, but when i run it as a cronjob (as myself or root) it doesnt work and throws out a useless error. only thing i can think of is i need to do something with the passwordless login bit of it (permissions or something maybe?)

originally posted at:
http://ubuntuforums.org/showthread.php? ... ost8327653

using ubuntu 9.10 32 bit. googling came up with the "Read the 'INVOCATION' section of bash(1) for more details" stuff, and all i could find that helped was to set the BASH_ENV variable in my crontab. which didnt help...


anyone?

------

me@babydweezil:~$ crontab -l
BASH_ENV=/home/me/.bashrc
# m h dom mon dow command
*/2 * * * * /home/me/watchcopy.sh
me@babydweezil:~$


watchcopy.sh:
#!/bin/sh
rsync -ave ssh --delete --include "*.filetype1" --include "*.filetype2" --exclude "*.*" --log-file=/home/me/watchrsync.log /media/1tb/downloads/chromedownloads/ user@externalbox:/data/me/watch


watchrsync.log:
2009/11/15 22:36:04 [6155] rsync: connection unexpectedly closed (0 bytes received so far) [sender]
2009/11/15 22:36:04 [6155] rsync error: unexplained error (code 255) at io.c(600) [sender=3.0.6]
2009/11/15 22:38:04 [6166] rsync: connection unexpectedly closed (0 bytes received so far) [sender]
2009/11/15 22:38:04 [6166] rsync error: unexplained error (code 255) at io.c(600) [sender=3.0.6]
and so on..... (repeated every 2 mins)
---
psn: spazhammer75
http://nottsdj.co.uk - Nottinghamshire Weddings and Events DJ
User avatar
defsdoor
Baaaaaa!
Baaaaaa!
Posts: 3909
Joined: Fri Jan 30, 2004 12:26 am 0
Location: Sunny Beduff

Re: The Official *nix Thread

Post by defsdoor »

Are you certain that your shared key authentication for that user is working ?
User avatar
Kelloggs
Baaaaa!
Baaaaa!
Posts: 1859
Joined: Wed Jun 22, 2005 11:38 pm 0
XBL Gamertag: TheAntiKelloggs
Location: Widnes or Altrincham. Take your pick.

Re: The Official *nix Thread

Post by Kelloggs »

I was doing pretty much the same thing yesterday. The passwordless thing would probably be the quickest to test - just run ssh-keygen on babydweezil (pressing Return twice when it asks for the passphrase) and add the resulting ~/.ssh/id_rsa.pub to the end of ~user/.ssh/authorized_keys on externalbox. Try ssh'ing to user@externalbox, and if that works, you've got passwordless login. Then try the rsync again.

NB: if babydweezil already has id_rsa and id_rsa.pub files in its .ssh directory, you're probably better reading the ssh-keygen man page and calling the files something different; at that point, your (otherwise simple) ssh command becomes ssh -i <id_rsa_equivalent> instead.

Season to taste.
User avatar
Dungeon-Dave
Baaaaaa!
Baaaaaa!
Posts: 3925
Joined: Thu Aug 04, 2005 12:01 pm 0
Location: UK
Contact:

Re: The Official *nix Thread

Post by Dungeon-Dave »

Remember that crontab (unlike at) doesn't make assumptions about the user's profile - ie: doesn't parse .bash_profile and the like before running - so some environment variables may not be set up and need to be specified within the script or explicitly on the command line, rather than let the command(s) take defaults.

This is usually a reason why manual commands work but crons fail. To test it, try:
1. "set > ~/login.env"
2. source that login.env file into the crontab script

If the crontab *now* works, it's likely to be reliant upon an environment variable (dunno which one - the mission is now to identify it!).
User avatar
wanye
Baaaaaa!
Baaaaaa!
Posts: 3047
Joined: Tue Sep 07, 2004 12:46 pm 0
PSN: wanye_m
Location: nottingham
Contact:

Re: The Official *nix Thread

Post by wanye »

Kelloggs wrote:I was doing pretty much the same thing yesterday. The passwordless thing would probably be the quickest to test - just run ssh-keygen on babydweezil (pressing Return twice when it asks for the passphrase) and add the resulting ~/.ssh/id_rsa.pub to the end of ~user/.ssh/authorized_keys on externalbox. Try ssh'ing to user@externalbox, and if that works, you've got passwordless login. Then try the rsync again.

NB: if babydweezil already has id_rsa and id_rsa.pub files in its .ssh directory, you're probably better reading the ssh-keygen man page and calling the files something different; at that point, your (otherwise simple) ssh command becomes ssh -i <id_rsa_equivalent> instead.

Season to taste.
passwordless definitely works, i've already tested that. cheers though.
Remember that crontab (unlike at) doesn't make assumptions about the user's profile - ie: doesn't parse .bash_profile and the like before running - so some environment variables may not be set up and need to be specified within the script or explicitly on the command line, rather than let the command(s) take defaults.

This is usually a reason why manual commands work but crons fail. To test it, try:
1. "set > ~/login.env"
2. source that login.env file into the crontab script

If the crontab *now* works, it's likely to be reliant upon an environment variable (dunno which one - the mission is now to identify it!).
cheers,
ill give this a try when i get home later
---
psn: spazhammer75
http://nottsdj.co.uk - Nottinghamshire Weddings and Events DJ
User avatar
defsdoor
Baaaaaa!
Baaaaaa!
Posts: 3909
Joined: Fri Jan 30, 2004 12:26 am 0
Location: Sunny Beduff

Re: The Official *nix Thread

Post by defsdoor »

If it were an environment issue the only thing that I can see from what you are doing that it could be is simply that ssh isn't in the path. I would expect a more explicit error though if that were the case.

It's always a good plan to fully path things though - it avoids the possibility of someone shortcutting your intended path with their own ssh program.
User avatar
Dungeon-Dave
Baaaaaa!
Baaaaaa!
Posts: 3925
Joined: Thu Aug 04, 2005 12:01 pm 0
Location: UK
Contact:

Re: The Official *nix Thread

Post by Dungeon-Dave »

I'm not convinced it's an environment issue either - just that one suggested workaround features setting a variable in the crontab which had my spidey sense tingling, and my suggestion should narrow down if it is/isn't.

Note that SSH could be looking in ${HOME}/.ssh for certs and if that's isn't set then cron will fail to find the known_hosts. (I don't know SSH well enough to know about the affect env vars have upon scp/rsync.. but I'm still interested in learning how to get this to work so that I can use it meself, mind!)

I'll agree that a more meaningful error message could aid diagnostics and troubleshooting; I've long learned not to be surprised at the gap between what to expect and what is actually delivered.
User avatar
wanye
Baaaaaa!
Baaaaaa!
Posts: 3047
Joined: Tue Sep 07, 2004 12:46 pm 0
PSN: wanye_m
Location: nottingham
Contact:

Re: The Official *nix Thread

Post by wanye »

didnt get chance to try out the env stuff last night as i was too busy trying to catch a hamster (not a euphemism!)

need to get this sorted asap though, as i dont think my gf will be too happy if things arent automated for her to download stuff from the server (i plan on automating the watch upload script then having a similar rsync to check the remote server and grab new files off there and drop them straight onto my NAS for streaming to the ps3)
---
psn: spazhammer75
http://nottsdj.co.uk - Nottinghamshire Weddings and Events DJ
User avatar
dom
Baaaaa!
Baaaaa!
Posts: 1370
Joined: Wed Feb 09, 2005 1:17 pm 0
Location: Edinburgh, UK and level 691859
Contact:

Re: The Official *nix Thread

Post by dom »

It sounds like there might be a simpler solution, e.g. mounting the NAS on the server and saving directly to there, or copying with "cp" to a seperately mounted directory which is exported from the NAS - do you absolutely need to use rsync?

Another solution which a friend of mine implements is simply to copy the files onto a USB pendrive and plug that into the PS3 to watch stuff, mainly because his Mrs doesn't like cable trailing around the house.

Just wondering, like.

Dom
OMG (or oligodendrocyte myelin glycoprotein) is a molecule found in your central nervous system.
User avatar
wanye
Baaaaaa!
Baaaaaa!
Posts: 3047
Joined: Tue Sep 07, 2004 12:46 pm 0
PSN: wanye_m
Location: nottingham
Contact:

Re: The Official *nix Thread

Post by wanye »

dom wrote:It sounds like there might be a simpler solution, e.g. mounting the NAS on the server and saving directly to there, or copying with "cp" to a seperately mounted directory which is exported from the NAS - do you absolutely need to use rsync?

Another solution which a friend of mine implements is simply to copy the files onto a USB pendrive and plug that into the PS3 to watch stuff, mainly because his Mrs doesn't like cable trailing around the house.

Just wondering, like.

Dom
i'm copying from my external server onto my NAS box for streaming to the ps3. the plan is for a cronjob running on the NAS to pull the files off once they are there, which should work normally, as i'm not using ubuntu (and not had any similar rsync issues with other *nix boxes ive used). my main issue is polling my desktop and finding files to upload to the external box to trigger downloads.

i might just set the NAS to do all the rsyncing if i still get problems with my ubuntu box...
---
psn: spazhammer75
http://nottsdj.co.uk - Nottinghamshire Weddings and Events DJ
User avatar
RageMatrix
Baaaaaaa!
Baaaaaaa!
Posts: 5515
Joined: Fri May 10, 2002 12:52 pm 0
XBL Gamertag: Jon256
Location: East Sussex

Re: The Official *nix Thread

Post by RageMatrix »

To my eternal shame, I've only ever messed with the firewall setup through the GNOME widget GUI. Now I need to open a port for the Nagios daemon on a machine at work to which I only have SSH terminal access. What does the GNOME firewall GUI link into? iptables?
XBox Gamertag: Jon256
Wii Code: 4849 1090 9042 6725
"Wrapped in metal, wrapped in ivy"
The Official UNIX/Linux Thread
User avatar
Dungeon-Dave
Baaaaaa!
Baaaaaa!
Posts: 3925
Joined: Thu Aug 04, 2005 12:01 pm 0
Location: UK
Contact:

Re: The Official *nix Thread

Post by Dungeon-Dave »

yup.

iptables -L -n = list rules

Most GUIs tend not to change live information, but edit the file containing the ruleset, something like /etc/sysconfig/iptables. Make changes to that file then:

/etc/init.d/iptables restart

Should reload the rules.
User avatar
RageMatrix
Baaaaaaa!
Baaaaaaa!
Posts: 5515
Joined: Fri May 10, 2002 12:52 pm 0
XBL Gamertag: Jon256
Location: East Sussex

Re: The Official *nix Thread

Post by RageMatrix »

Cheers Dave :)
XBox Gamertag: Jon256
Wii Code: 4849 1090 9042 6725
"Wrapped in metal, wrapped in ivy"
The Official UNIX/Linux Thread
User avatar
RageMatrix
Baaaaaaa!
Baaaaaaa!
Posts: 5515
Joined: Fri May 10, 2002 12:52 pm 0
XBL Gamertag: Jon256
Location: East Sussex

Re: The Official *nix Thread

Post by RageMatrix »

Okay, bit of an odd one this. My server has two hard disks - one is a fairly old 120GB IDE drive (sda) and the other is a six-month old 500GB IDE drive (sdb). The /home partition is mounted on the 500GB sdb drive, whilst the OS is on the 120GB sda drive.

I was uploading about 32GB of data to the 500GB drive when it suddenly stopped. Checking the filesystem, it had gone into read-only mode which tends to suggest a hard problem. Rebooted and tried again with smaller amount of data - same problem. Rebooted and there was a clicking sound from the sda drive and no booting. Another reboot and back to normal.

Now, I'm pretty sure the 120GB drive is failing. Fair enough, it's pretty old. I've run the smartctl command, which is control and monitor utility for SMART disks under Linux as both drives are SMART enabled so I'm running a self-test at the moment (which should be done by 11:50am :D).

Preliminary tests show: -

Code: Select all

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

=== START OF READ SMART DATA SECTION ===
SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000b   200   189   051    Pre-fail  Always       -       0
  3 Spin_Up_Time            0x0007   205   151   021    Pre-fail  Always       -       2775
  4 Start_Stop_Count        0x0032   099   099   040    Old_age   Always       -       1379
  5 Reallocated_Sector_Ct   0x0033   199   199   140    Pre-fail  Always       -       13
  7 Seek_Error_Rate         0x000b   100   253   051    Pre-fail  Always       -       0
  9 Power_On_Hours          0x0032   042   042   000    Old_age   Always       -       42782
 10 Spin_Retry_Count        0x0013   100   100   051    Pre-fail  Always       -       0
 11 Calibration_Retry_Count 0x0013   100   100   051    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   099   099   000    Old_age   Always       -       1301
196 Reallocated_Event_Count 0x0032   191   191   000    Old_age   Always       -       9
197 Current_Pending_Sector  0x0012   200   200   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0012   200   200   000    Old_age   Always       -       0
199 UDMA_CRC_Error_Count    0x000a   200   200   000    Old_age   Always       -       42
200 Multi_Zone_Error_Rate   0x0009   200   200   051    Pre-fail  Offline      -       0

SMART Self-test log structure revision number 1
No self-tests have been logged.  [To run self-tests, use: smartctl -t]

=== START OF INFORMATION SECTION ===
Model Family:     Western Digital Caviar family
Device Model:     WDC WD1200BB-00DAA3
Serial Number:    WD-WMACK1807499
Firmware Version: 75.13B75
User Capacity:    120,034,123,776 bytes
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   6
ATA Standard is:  Exact ATA specification draft version not indicated
Local Time is:    Tue Jan  5 09:23:15 2010 GMT
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

General SMART Values:
Offline data collection status:  (0x84) Offline data collection activity
                                        was suspended by an interrupting command from host.
                                        Auto Offline Data Collection: Enabled.
Self-test execution status:      (   0) The previous self-test routine completed
                                        without error or no self-test has ever
                                        been run.
Total time to complete Offline
data collection:                 (4585) seconds.
Offline data collection
capabilities:                    (0x7b) SMART execute Offline immediate.
                                        Auto Offline data collection on/off support.
                                        Suspend Offline collection upon new
                                        command.
                                        Offline surface scan supported.
                                        Self-test supported.
                                        Conveyance Self-test supported.
                                        Selective Self-test supported.
SMART capabilities:            (0x0003) Saves SMART data before entering
                                        power-saving mode.
                                        Supports SMART auto save timer.
Error logging capability:        (0x01) Error logging supported.
                                        No General Purpose Logging support.
Short self-test routine
recommended polling time:        (   2) minutes.
Extended self-test routine
recommended polling time:        (  61) minutes.
Conveyance self-test routine
recommended polling time:        (   5) minutes.

SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000b   200   189   051    Pre-fail  Always       -       0
  3 Spin_Up_Time            0x0007   205   151   021    Pre-fail  Always       -       2775
  4 Start_Stop_Count        0x0032   099   099   040    Old_age   Always       -       1379
  5 Reallocated_Sector_Ct   0x0033   199   199   140    Pre-fail  Always       -       13
  7 Seek_Error_Rate         0x000b   100   253   051    Pre-fail  Always       -       0
  9 Power_On_Hours          0x0032   042   042   000    Old_age   Always       -       42782
 10 Spin_Retry_Count        0x0013   100   100   051    Pre-fail  Always       -       0
 11 Calibration_Retry_Count 0x0013   100   100   051    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   099   099   000    Old_age   Always       -       1301
196 Reallocated_Event_Count 0x0032   191   191   000    Old_age   Always       -       9
197 Current_Pending_Sector  0x0012   200   200   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0012   200   200   000    Old_age   Always       -       0
199 UDMA_CRC_Error_Count    0x000a   200   200   000    Old_age   Always       -       42
200 Multi_Zone_Error_Rate   0x0009   200   200   051    Pre-fail  Offline      -       0

SMART Error Log Version: 1
ATA Error Count: 37 (device log contains only the most recent five errors)
        CR = Command Register [HEX]
        FR = Features Register [HEX]
        SC = Sector Count Register [HEX]
        SN = Sector Number Register [HEX]
        CL = Cylinder Low Register [HEX]
        CH = Cylinder High Register [HEX]
        DH = Device/Head Register [HEX]
        DC = Device Command Register [HEX]
        ER = Error register [HEX]
        ST = Status register [HEX]
Powered_Up_Time is measured from power on, and printed as
DDd+hh:mm:SS.sss where DD=days, hh=hours, mm=minutes,
SS=sec, and sss=millisec. It "wraps" after 49.710 days.

Error 37 occurred at disk power-on lifetime: 625 hours (26 days + 1 hours)
  When the command that caused the error occurred, the device was doing SMART Offline or Self-test.

  After command completion occurred, registers were:
  ER ST SC SN CL CH DH
  -- -- -- -- -- -- --
  40 51 08 52 40 87 e5  Error:

  Commands leading to the command that caused the error were:
  CR FR SC SN CL CH DH DC   Powered_Up_Time  Command/Feature_Name
  -- -- -- -- -- -- -- --  ----------------  --------------------
  00 00 c8 00 00 08 00 00   9d+22:21:27.800  NOP [Abort queued commands]
  00 00 5e 00 00 3f 00 00   9d+22:21:27.800  NOP [Abort queued commands]
  00 00 c8 00 00 08 00 00   9d+22:21:27.800  NOP [Abort queued commands]
  0c 00 2a 00 00 cf fc 00   9d+22:21:27.800  [RESERVED]
  00 00 c8 00 00 08 00 00   9d+22:21:27.800  NOP [Abort queued commands]

Error 36 occurred at disk power-on lifetime: 625 hours (26 days + 1 hours)
  When the command that caused the error occurred, the device was doing SMART Offline or Self-test.

  After command completion occurred, registers were:
  ER ST SC SN CL CH DH
  -- -- -- -- -- -- --
  40 51 08 52 40 87 e5  Error:

  Commands leading to the command that caused the error were:
  CR FR SC SN CL CH DH DC   Powered_Up_Time  Command/Feature_Name
  -- -- -- -- -- -- -- --  ----------------  --------------------
  00 00 c8 00 00 08 00 00   9d+22:21:23.550  NOP [Abort queued commands]
  00 00 00 00 00 00 00 00   9d+22:21:23.550  NOP [Abort queued commands]
  00 00 ca 00 00 08 00 00   9d+22:21:23.550  NOP [Abort queued commands]
  0a 00 cb 00 00 c7 e0 00   9d+22:21:23.550  [RESERVED]
  00 00 c8 00 00 40 00 00   9d+22:21:23.550  NOP [Abort queued commands]

[b]Error 35 occurred at disk power-on lifetime: 625 hours (26 days + 1 hours)
  When the command that caused the error occurred, the device was doing SMART Offline or Self-test.[/b]

  After command completion occurred, registers were:
  ER ST SC SN CL CH DH
  -- -- -- -- -- -- --
  40 51 08 52 40 87 e5  Error:

  Commands leading to the command that caused the error were:
  CR FR SC SN CL CH DH DC   Powered_Up_Time  Command/Feature_Name
  -- -- -- -- -- -- -- --  ----------------  --------------------
  00 00 c8 00 00 08 00 00   9d+22:21:19.250  NOP [Abort queued commands]
  00 00 5e 00 00 bf 8c 00   9d+22:21:19.250  NOP [Abort queued commands]
  00 00 c8 00 00 01 00 00   9d+22:21:19.250  NOP [Abort queued commands]
  0a 00 cb 00 00 df 1d 00   9d+22:21:19.250  [RESERVED]
  00 00 c8 00 00 08 00 00   9d+22:21:19.250  NOP [Abort queued commands]

[b]Error 34 occurred at disk power-on lifetime: 625 hours (26 days + 1 hours)
  When the command that caused the error occurred, the device was doing SMART Offline or Self-test.[/b]

  After command completion occurred, registers were:
  ER ST SC SN CL CH DH
  -- -- -- -- -- -- --
  40 51 38 52 40 87 e5  Error:

  Commands leading to the command that caused the error were:
  CR FR SC SN CL CH DH DC   Powered_Up_Time  Command/Feature_Name
  -- -- -- -- -- -- -- --  ----------------  --------------------
  00 00 c8 00 00 38 00 00   9d+22:21:14.850  NOP [Abort queued commands]
  [b]03 00 de 00 00 bf 26 00   9d+22:21:14.850  CFA REQUEST EXTENDED ERROR CODE[/b]
  00 00 ca 00 00 08 00 00   9d+22:21:14.850  NOP [Abort queued commands]
  00 00 ca 00 00 50 00 00   9d+22:21:14.850  NOP [Abort queued commands]
  00 00 00 00 00 00 00 00   9d+22:21:14.850  NOP [Abort queued commands]

[b]Error 33 occurred at disk power-on lifetime: 625 hours (26 days + 1 hours)
  When the command that caused the error occurred, the device was doing SMART Offline or Self-test.[/b]

  After command completion occurred, registers were:
  ER ST SC SN CL CH DH
  -- -- -- -- -- -- --
  40 51 40 52 40 87 e5  Error:

  Commands leading to the command that caused the error were:
  CR FR SC SN CL CH DH DC   Powered_Up_Time  Command/Feature_Name
  -- -- -- -- -- -- -- --  ----------------  --------------------
  00 00 c8 00 00 40 00 00   9d+22:21:10.600  NOP [Abort queued commands]
  00 00 c8 00 00 08 00 00   9d+22:21:10.600  NOP [Abort queued commands]
  00 00 c2 00 00 f7 83 00   9d+22:21:10.600  NOP [Abort queued commands]
  00 00 ca 00 00 08 00 00   9d+22:21:10.600  NOP [Abort queued commands]
  0a 00 d2 00 00 37 cd 00   9d+22:21:10.600  [RESERVED]

SMART Self-test log structure revision number 1
No self-tests have been logged.  [To run self-tests, use: smartctl -t]


SMART Selective self-test log data structure revision number 1
 SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
    1        0        0  Not_testing
    2        0        0  Not_testing
    3        0        0  Not_testing
    4        0        0  Not_testing
    5        0        0  Not_testing
Selective self-test flags (0x0):
  After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.
So looks like 120GB sda drive is failing. But if the OS is on this drive and I was uploading via SSH to the second drive which went into read-only lockdown but has no errors that I can see (so far - running tests), could the sda drive cause the sdb drive to go into "lockdown" if there was a problem?

Basically, which drive is buggered? :) I find it hard to believe that both are dying at the same time.
XBox Gamertag: Jon256
Wii Code: 4849 1090 9042 6725
"Wrapped in metal, wrapped in ivy"
The Official UNIX/Linux Thread
User avatar
WiteWulf
Sheepie Whore
Sheepie Whore
Posts: 10125
Joined: Mon Aug 23, 2004 11:20 am 0
PSN: WiteWulf
Location: Loughborough(ish)

Re: The Official *nix Thread

Post by WiteWulf »

Where's your swap and/or /tmp located? If they're on /dev/sda I'd imagine that'd bring the whole system down if the drive goes into RO mode.
:::G:::

PSN: WiteWulf
Switch: SW-3941-2878-7584
Steam: WITEWULF66
Post Reply