LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 03-27-2012, 01:47 PM   #1
WarTurkey
Member
 
Registered: Jun 2009
Posts: 67

Rep: Reputation: 16
Debian ~/.bash_profile execution error


Okay, so I made a thread earlier about how I am working on making a server which will allow two nodes to boot up and re-image themselves from an image residing on a second partition of their drives. I successfully got them to the point that they boot up and I can run a script I made, which is /usr/bin/restore.

When I boot up, I can enter the word, "restore," on the command line, and the script works without error. All it does is call another script with sudo, which contains the following:
Code:
#!/bin/bash
#
# Super-User part of restore script
mkdir /mnt/source
mount -t ext2 -o ro /dev/sda2 /mnt/source
echo Restoring boot sector...
dd if=/mnt/source/bootsect.dd of=/dev/sda
echo Restoring partition...
dd if=/mnt/source/Recover.dd of=/dev/sda1 bs=32768
echo Done.  Restarting...
reboot
The thing is, however, that I would like to eliminate the need for entering this command. I would prefer if the computers simply booted up, restored themselves, and then restarted. The problem I'm having, is that when I add the word, "restore" to the end of my ~/.bash_profile script, the computer boots up, but then prints a whole bunch of errors and reboots before I can see what happened. I'm currently building the image with "reboot" removed from the end, to see what exactly is going on.

I don't understand how a script that when typed, will function perfectly, however if it is run from "~/.bash_profile," it has errors. Other than the way the script is called, there is no difference.
 
Old 03-27-2012, 01:54 PM   #2
WarTurkey
Member
 
Registered: Jun 2009
Posts: 67

Original Poster
Rep: Reputation: 16
I removed "reboot" from the end, and now it works. But why is it rebooting before it executes the first lines? And now I still need to use the "reboot" command, so it doesn't eliminate the need to type. Still working on it.
 
Old 03-27-2012, 10:34 PM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Puzzling. Keep us posted
 
Old 03-28-2012, 07:29 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Perhaps it's running too quickly?

The dd command could be starting before the mount is fully completed. Try adding a short sleep between commands and see if that helps. Something like:

Code:
until [ -f "/mnt/source/bootsect.dd" ]; do
	sleep 1
done
You can also try redirecting the output, or at least the output of the critical commands, to a permanent log file, so you can see what the errors are.
 
Old 03-28-2012, 08:37 AM   #5
WarTurkey
Member
 
Registered: Jun 2009
Posts: 67

Original Poster
Rep: Reputation: 16
Okay, I don't understand why, but when called from ~/.bash_profile or ~/.profile, mount fails with "unknown filesystem type 'ext2'" How does that make sense? By the time the shell is invoked, filesystem modules are already loaded, right? I'll try the sleep commands though. The only thing that's changed is the speed at which the script is called! I'll see what happens...
 
Old 03-28-2012, 08:50 AM   #6
WarTurkey
Member
 
Registered: Jun 2009
Posts: 67

Original Poster
Rep: Reputation: 16
Alright, thanks David the H., you are right: It was being called too quickly. I used the exact until-loop you posted, and it works. It's still strange that it initially fails with ext2 being an unknown filesystem.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
.bash_profile help, : error while loading shared libraries: librt.so.1 sampappachan_nyc Linux - Server 1 09-02-2010 05:51 PM
[SOLVED] bash_profile in Debian Lenny riganta Linux - Laptop and Netbook 10 01-16-2009 12:03 PM
Java execution error NL-Stitch Programming 3 03-24-2007 12:44 PM
Error encountered in LFS v6.0 Ch. 4 .bash_profile mbreslin1954 Linux From Scratch 2 04-19-2005 09:54 AM
script execution error linux_lover2005 Programming 3 12-22-2004 06:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 12:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration