Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › Shell script to backup my files and folder not working
New Posts  All Forums:Forum Nav:

Shell script to backup my files and folder not working - Page 2

post #11 of 17
You are right that tilde is a function of the shell and not a env var.
http://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html

However, the tilde just returns value of $HOME. If $HOME is null, then it returns `whoami`. So if the $HOME value is null, then tilde will not work for his needs.
Code:
>echo ~
/home/someone
>unset HOME
>echo ~    
someone

Edited by DuckieHo - 11/5/13 at 11:24am
Once again...
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 [4.28GHz, HT] Asus P6T + Broadcom NetXtreme II VisionTek HD5850 [900/1200] + Galaxy GT240 2x4GB G.Skill Ripjaw X [1632 MHz] 
Hard DriveOSMonitorKeyboard
Intel X25-M 160GB + 3xRAID0 500GB 7200.12 Window 7 Pro 64 Acer H243H + Samsung 226BW XARMOR-U9BL  
PowerCaseMouseMouse Pad
Antec Truepower New 750W Li Lian PC-V2100 [10x120mm fans] Logitech G9 X-Trac Pro 
  hide details  
Reply
Once again...
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 [4.28GHz, HT] Asus P6T + Broadcom NetXtreme II VisionTek HD5850 [900/1200] + Galaxy GT240 2x4GB G.Skill Ripjaw X [1632 MHz] 
Hard DriveOSMonitorKeyboard
Intel X25-M 160GB + 3xRAID0 500GB 7200.12 Window 7 Pro 64 Acer H243H + Samsung 226BW XARMOR-U9BL  
PowerCaseMouseMouse Pad
Antec Truepower New 750W Li Lian PC-V2100 [10x120mm fans] Logitech G9 X-Trac Pro 
  hide details  
Reply
post #12 of 17
Quote:
Originally Posted by DuckieHo View Post

You are right that tilde is a function of the shell and not a env var.
http://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html

However, the tilde just returns value of $HOME. If $HOME is null, then it returns `whoami`. So if the $HOME value is null, then tilde will not work for his needs.
Code:
>echo ~
/home/someone
>unset HOME
>echo ~    
someone

I don't mean to be rude, but I'd already posted output that disproved this post. However I think since it's a shell function, it's fair to say that it's behaviour could be shell specific.

Anyhow, since my example was done in Bash and the OP's script is executing in Bash, I still think tilda will work. Failing that, I've also posted two workarounds. But in all honesty, the suggestion to hardcode the path isn't a bad one either since it doesn't appear to be a script that would gain any benefit from dynamically locating the home directory.

As an aside note, some builds of cron allow you to set env vars in the crontab itself. But since there's a few different cron daemons out there (GNU mcron and crony are the 1st two that spring to mind, but there's a few others), it's best not to depend on that in my opinion.
Edited by Plan9 - 11/5/13 at 11:53am
post #13 of 17
Quote:
Originally Posted by Plan9 View Post

I don't mean to be rude, but I'd already posted output that disproved this post. However I think since it's a shell function, it's fair to say that it's behaviour could be shell specific.

Anyhow, since my example was done in Bash and the OP's script is executing in Bash, I still think tilda will work. Failing that, I've also posted two workarounds.

You're right... it is shell specific. I forgot this older server is still in ksh by default. thumb.gif
Once again...
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 [4.28GHz, HT] Asus P6T + Broadcom NetXtreme II VisionTek HD5850 [900/1200] + Galaxy GT240 2x4GB G.Skill Ripjaw X [1632 MHz] 
Hard DriveOSMonitorKeyboard
Intel X25-M 160GB + 3xRAID0 500GB 7200.12 Window 7 Pro 64 Acer H243H + Samsung 226BW XARMOR-U9BL  
PowerCaseMouseMouse Pad
Antec Truepower New 750W Li Lian PC-V2100 [10x120mm fans] Logitech G9 X-Trac Pro 
  hide details  
Reply
Once again...
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 [4.28GHz, HT] Asus P6T + Broadcom NetXtreme II VisionTek HD5850 [900/1200] + Galaxy GT240 2x4GB G.Skill Ripjaw X [1632 MHz] 
Hard DriveOSMonitorKeyboard
Intel X25-M 160GB + 3xRAID0 500GB 7200.12 Window 7 Pro 64 Acer H243H + Samsung 226BW XARMOR-U9BL  
PowerCaseMouseMouse Pad
Antec Truepower New 750W Li Lian PC-V2100 [10x120mm fans] Logitech G9 X-Trac Pro 
  hide details  
Reply
post #14 of 17
Thread Starter 
I still don't follow.
Sunkissed Beauty
(26 items)
 
Quirky
(12 items)
 
CPUMotherboardGraphicsRAM
Intel Core i7 3770K [ 4.5Ghz | 1.370V ] AsRock Z77 OC Formula ASUS GTX 760 DC2OC-2GD5 [ 1202/3506 ] Crucial Ballistix Elite 16GB 1866Mhz CL9 1.5V [... 
Hard DriveHard DriveHard DriveHard Drive
Crucial MX100 256GB Western Digital Caviar Blue 500GB [ WD5000AAKX ] Western Digital Caviar Blue 1TB [ WD10EZEX ] Western Digital Caviar Green 1TB [ WD10EARS ] 
Hard DriveCoolingCoolingCooling
Western Digital Caviar Green 1TB [ WD10EARS ] Corsair H100i Push&Pull Corsair SP120L PWM [ 2X] [ H100i ] Corsair SP120 PWM High Peformance [ 2X ][ H100 i] 
CoolingCoolingOSMonitor
NZXT FN 140RB [4X][Case] Cooler Master Sickleflow 120 Red [ 2X ][ Case ] Windows 10 Pro x64 Samsung B2230 
KeyboardPowerCaseMouse
Corsair Vengeance K95 RGB [ MX Brown ] Seasonic X760 NZXT Swtich 810 Black Logitech G402 
Mouse PadAudioAudioAudio
Razer Goliathus Alpha Control / Steelseries Qck... Sennheiser HD 429 Creative Inspire T7900 ASUS Xonar DGX 
OtherOther
NZXT Sentry LX NZXT Sleeved LED Kit | Orange 2M 
CPUMotherboardGraphicsOptical Drive
Intel Pentium Dual-Core E2200 MSI 945GCM5-F V2 (FSB 1333) Inno3D Nvidia GeForce GTS 450 1GB (Cooler Ripoff) Benq DVD-R,CD-R,DVD-ROM,CD-ROM 
CoolingMonitorKeyboardPower
Intel Stock Fan MAG InnoVision 770FS Logitech Internet Pro AcBel R8 PowerII 650W 80+ 
CaseMouseMouse PadAudio
Vertu Santa Fe "Blue" Logitech Internet Pro CM Storm Pad Sound Blaster Audigy 2 ZS 
  hide details  
Reply
Sunkissed Beauty
(26 items)
 
Quirky
(12 items)
 
CPUMotherboardGraphicsRAM
Intel Core i7 3770K [ 4.5Ghz | 1.370V ] AsRock Z77 OC Formula ASUS GTX 760 DC2OC-2GD5 [ 1202/3506 ] Crucial Ballistix Elite 16GB 1866Mhz CL9 1.5V [... 
Hard DriveHard DriveHard DriveHard Drive
Crucial MX100 256GB Western Digital Caviar Blue 500GB [ WD5000AAKX ] Western Digital Caviar Blue 1TB [ WD10EZEX ] Western Digital Caviar Green 1TB [ WD10EARS ] 
Hard DriveCoolingCoolingCooling
Western Digital Caviar Green 1TB [ WD10EARS ] Corsair H100i Push&Pull Corsair SP120L PWM [ 2X] [ H100i ] Corsair SP120 PWM High Peformance [ 2X ][ H100 i] 
CoolingCoolingOSMonitor
NZXT FN 140RB [4X][Case] Cooler Master Sickleflow 120 Red [ 2X ][ Case ] Windows 10 Pro x64 Samsung B2230 
KeyboardPowerCaseMouse
Corsair Vengeance K95 RGB [ MX Brown ] Seasonic X760 NZXT Swtich 810 Black Logitech G402 
Mouse PadAudioAudioAudio
Razer Goliathus Alpha Control / Steelseries Qck... Sennheiser HD 429 Creative Inspire T7900 ASUS Xonar DGX 
OtherOther
NZXT Sentry LX NZXT Sleeved LED Kit | Orange 2M 
CPUMotherboardGraphicsOptical Drive
Intel Pentium Dual-Core E2200 MSI 945GCM5-F V2 (FSB 1333) Inno3D Nvidia GeForce GTS 450 1GB (Cooler Ripoff) Benq DVD-R,CD-R,DVD-ROM,CD-ROM 
CoolingMonitorKeyboardPower
Intel Stock Fan MAG InnoVision 770FS Logitech Internet Pro AcBel R8 PowerII 650W 80+ 
CaseMouseMouse PadAudio
Vertu Santa Fe "Blue" Logitech Internet Pro CM Storm Pad Sound Blaster Audigy 2 ZS 
  hide details  
Reply
post #15 of 17
Basically $HOME isn't set. Try this:
Code:
#!/bin/bash

HOME=$(getent passwd $(whoami) | cut -d: -f6)
NOWDATE=`date +%m%d%y`

#section for website backup
mkdir -p $HOME/html/Site_CRON_Backup/test.com # create site directory if it doesn't already exist
tar -cvzPfp --same-permissions $HOME/html/Site_CRON_Backup/test.com/_testcom_$NOWDATE.tar.gz $HOME/html/test.com/ # zip site files
post #16 of 17
Quote:
Originally Posted by Speedster159 View Post

I still don't follow.

HOME works when you experiment with things. But do you know what happens when your script runs through cron? Will it run as your user and will the shell that gets started load all configuration files to set that HOME variable?
post #17 of 17
Thread Starter 
Well i have this crude script to make a mysql dump of my databases and it works by using $HOME.
Sunkissed Beauty
(26 items)
 
Quirky
(12 items)
 
CPUMotherboardGraphicsRAM
Intel Core i7 3770K [ 4.5Ghz | 1.370V ] AsRock Z77 OC Formula ASUS GTX 760 DC2OC-2GD5 [ 1202/3506 ] Crucial Ballistix Elite 16GB 1866Mhz CL9 1.5V [... 
Hard DriveHard DriveHard DriveHard Drive
Crucial MX100 256GB Western Digital Caviar Blue 500GB [ WD5000AAKX ] Western Digital Caviar Blue 1TB [ WD10EZEX ] Western Digital Caviar Green 1TB [ WD10EARS ] 
Hard DriveCoolingCoolingCooling
Western Digital Caviar Green 1TB [ WD10EARS ] Corsair H100i Push&Pull Corsair SP120L PWM [ 2X] [ H100i ] Corsair SP120 PWM High Peformance [ 2X ][ H100 i] 
CoolingCoolingOSMonitor
NZXT FN 140RB [4X][Case] Cooler Master Sickleflow 120 Red [ 2X ][ Case ] Windows 10 Pro x64 Samsung B2230 
KeyboardPowerCaseMouse
Corsair Vengeance K95 RGB [ MX Brown ] Seasonic X760 NZXT Swtich 810 Black Logitech G402 
Mouse PadAudioAudioAudio
Razer Goliathus Alpha Control / Steelseries Qck... Sennheiser HD 429 Creative Inspire T7900 ASUS Xonar DGX 
OtherOther
NZXT Sentry LX NZXT Sleeved LED Kit | Orange 2M 
CPUMotherboardGraphicsOptical Drive
Intel Pentium Dual-Core E2200 MSI 945GCM5-F V2 (FSB 1333) Inno3D Nvidia GeForce GTS 450 1GB (Cooler Ripoff) Benq DVD-R,CD-R,DVD-ROM,CD-ROM 
CoolingMonitorKeyboardPower
Intel Stock Fan MAG InnoVision 770FS Logitech Internet Pro AcBel R8 PowerII 650W 80+ 
CaseMouseMouse PadAudio
Vertu Santa Fe "Blue" Logitech Internet Pro CM Storm Pad Sound Blaster Audigy 2 ZS 
  hide details  
Reply
Sunkissed Beauty
(26 items)
 
Quirky
(12 items)
 
CPUMotherboardGraphicsRAM
Intel Core i7 3770K [ 4.5Ghz | 1.370V ] AsRock Z77 OC Formula ASUS GTX 760 DC2OC-2GD5 [ 1202/3506 ] Crucial Ballistix Elite 16GB 1866Mhz CL9 1.5V [... 
Hard DriveHard DriveHard DriveHard Drive
Crucial MX100 256GB Western Digital Caviar Blue 500GB [ WD5000AAKX ] Western Digital Caviar Blue 1TB [ WD10EZEX ] Western Digital Caviar Green 1TB [ WD10EARS ] 
Hard DriveCoolingCoolingCooling
Western Digital Caviar Green 1TB [ WD10EARS ] Corsair H100i Push&Pull Corsair SP120L PWM [ 2X] [ H100i ] Corsair SP120 PWM High Peformance [ 2X ][ H100 i] 
CoolingCoolingOSMonitor
NZXT FN 140RB [4X][Case] Cooler Master Sickleflow 120 Red [ 2X ][ Case ] Windows 10 Pro x64 Samsung B2230 
KeyboardPowerCaseMouse
Corsair Vengeance K95 RGB [ MX Brown ] Seasonic X760 NZXT Swtich 810 Black Logitech G402 
Mouse PadAudioAudioAudio
Razer Goliathus Alpha Control / Steelseries Qck... Sennheiser HD 429 Creative Inspire T7900 ASUS Xonar DGX 
OtherOther
NZXT Sentry LX NZXT Sleeved LED Kit | Orange 2M 
CPUMotherboardGraphicsOptical Drive
Intel Pentium Dual-Core E2200 MSI 945GCM5-F V2 (FSB 1333) Inno3D Nvidia GeForce GTS 450 1GB (Cooler Ripoff) Benq DVD-R,CD-R,DVD-ROM,CD-ROM 
CoolingMonitorKeyboardPower
Intel Stock Fan MAG InnoVision 770FS Logitech Internet Pro AcBel R8 PowerII 650W 80+ 
CaseMouseMouse PadAudio
Vertu Santa Fe "Blue" Logitech Internet Pro CM Storm Pad Sound Blaster Audigy 2 ZS 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › Shell script to backup my files and folder not working