Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hey guys, im running macosx 10.4.4 which of course uses linux under neath and ive been trying to write up a script for both my mac and linux box, but at the momment it seems the script hits a halt during the archive bit
Code:
#! /bin/bash
#----Backup Details------------------------#
BACKUPNAME="xxxxx"
BACKUPDIR="~/"
NAMET=~/$BACKUPNAME-$(date +%d%m%Y).tar.gz
NAMEE=~/$BACKUPNAME-$(date +%d%m%Y).aes
REMOVETEMP=1
#----Online Backup details-----------------#
ONLINE=1
FTPUSER=xxxxx
FTPPASS=xxxxx
FTPDIR=xxxxxx
FTPSITE=xxxxxx
#----Server Backup Details-----------------#
SERVER=1
BACKUPDRIVE=xxxxx
SHARE=xxxxx
SMBSERVER=xxxxxx
#----Encryption Details--------------------#
ENCRYPTBACKUP=1
ENCRYPTPASS=xxxxxxx
function BACKUPFTP {
growlnotify -m "Uploading backup to FTP" -t $BACKUPNAME
echo "uploading to ftp"
if [ ENCRYPTBACKUP = 1]; then
ftp -n <<EOF
open $FTPUSER $FTPSITE
user $FTPPASS
put $NAMEE $FTPDIR
bye
EOF
elif [ENCRYPTBACKUP = 0]; then
ftp -n <<EOF
open $FTPUSER $FTPSITE
user $FTPPASS
put $NAMET $FTPDIR
bye
EOF
fi
}
function REMOVETEMP {
#removes archive
echo "removing archives"
growlnotify -m "Removing Files used" -t $BACKUPNAME
rm $NAMET
rm $NAMEE
}
function ENCRYPT {
#Encrypts the archive
echo "encrypting files"
growlnotify -m "Encrypting backup" -t $BACKUPNAME
openssl enc -e -a -salt -aes-256-cbc -in $NAMET -out $NAMEE -k $ENCRYPTPASS
}
function MOUNTSHARE {
#mounts the backup drive
echo "Mounting backupdrive"
growlnotify -m "Mounting Backup Drive" -t $BACKUPNAME
mount_smbfs -I $SMBSERVER $SHARE $BACKUPDRIVE
}
#unmounts the backupdrive
function UNMOUNTSERVER {
echo "unmounting backupdrive"
growlnotify -m "Unmounting backupdrive" -t $BACKUPNAME
umount $BACKUPDIR
}
function UPLOADSERVER {
echo "Uploading archive to server"
growlnotify -m "Copying to Backup Drive" -t $BACKUPNAME
if [ BACKUPDRIVE = 1]; then
cp $NAMEE $BACKUPDRIVE
elif [BACKUPDRIVE = 0]; then
cp $NAMET $BACKUPDRIVE
fi
}
#Archives the files
function ARCHIVE {
echo "archiving files"
growlnotify -m "Archiving backup" -t $BACKUPNAME
tar -czf $NAMET $BACKUPDIR
}
echo "Annoucing Backup"
growlnotify -m "Backup Started" -t $BACKUPNAME -s
ARCHIVE
if [ "ENCRYPTBACKUP" = "1" ]; then
ENCRYPT
fi
if [ "ONLINE" = "1" ]; then
BACKUPFTP
fi
if [ "SERVER" = "1" ]; then
MOUNTSHARE
UPLOADSERVER
UNMOUNTSERVER
fi
if [ "CLEANUP" = "1" ]; then
REMOVETEMP
fi
growlnotify -m "Backup COMPLETED" -t $BACKUPNAME -s
well its not exactly linux but much in the terminal is near the same cmds as a linux machine, anywho the fact is this is about bash scripting which both have, so can someone help me and tell me if anything is wrong with it
Read the man pages. I suppose there is a possibility to include other files (like the #include in C).
For instance, in the /etc/init.d/* scripts, often written in Bash, the script /etc/init.d/functions is usually "included" by:
. ./etc/init.d/functions
Also, you should pay attention to programming syntax. Several shells have different if-syntax for numeric comparisons (called "ARITHMETIC EVALUATION") and for string/other comparisons. So, if your variable stores a number, you should use the number syntax, not the string syntax, etc.
If you want to test if a number equals 1 in Bash, I think it's supposed to be written as:
if (( $num == 1 )); then
do_some_code;
fi;
But, to test if a file exists, you need to use:
if [[ -f $file_name ]]; then
do_some_code;
fi;
In short, read "man bash", like the rest of us - lol
Hey guys, this one is a new question but ill stay in one thread, im trying to build a few scripts for my suse 10 box but when ever i try to run the script i get this
bender:/home/gserver # ./utilities.sh
: bad interpreter: No such file or directory
Code:
#!/bin/bash
UTILITES="CSMAPLIST REBOOT SHUTDOWN"
select utl in $UTILITES; do
if [ "$utl" = "CSMAPLIST" ]; then
echo "Listing Counter Strike maps.."
cat | ls /home/gserver/games/csmaps
elif [ "$utl" = "REBOOT" ]; then
sudo init 6
elif [ "$utl" = "SHUTDOWN" ]; then
sudo shutdown now
else
echo
echo
echo ERROR : BAD OPTION, TRY AGAIN
fi
done
Basically, #!/bin/bash tells your system that it should use the bash shell (the program /bin/bash) to interprete the code below that line.
In other words, your script uses the Bash shell syntax.
However the error "bad interpreter" suggests that you don't have the /bin/bash program.
Try doing
ls -l /bin/bash
whereis bash
If they don't tell you that you have bash, you probably don't have it. /bin/sh is similar, but somewhat older and thus may lack some features of Bash. Try changing #!/bin/bash into #!/bin/sh and run the script again to see if it works.
Otherwise,
echo $SHELL
to print the shell you're currently using. You could try re-writing your script using that shell (and it's specific syntax) as well.
EDIT: ok my mistake it seems that my windows notepad2 i had been using had placed werid formatting to it even tho its txt, is there any good notepad apps that do the colouring of text for certain functions
PS. i know about vim but thats just all one colour
im sure bash is there and working becuase i have other scripts that load and run fine, i copied that direct line from another script that i know works.
On Windows, you could try using a professional editor rather than notepad or wordpad (that won't do syntax highlighting).
Try something like TextPad or UltraEdit. You can try them for free, but have to pay for a license.
As for vim, it shouldn't put everything in just one colour. My vim recognizes my scripts and source code just fine and highlights the syntax correctly. If that's not the case for you, I'd recommend you taking a look at your syntax. Maybe you've accidentally commented out everything or disabled syntax highlighting?
If you want other editors then vim, try using a graphical one, like gedit, nedit, kedit, etc.
Search this forum for others.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.