ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I need to grab some CSV files from a remote location.
I will probably either get HTTP or SSH access.
If I'm only granted HTTP access, what would be the most secure way to grab the file?
I figure I can use wget using HTTPS. But what if I only get SSH access? I could use 'scp' but how do I get around the password prompt because this will be cronjob?
Also, how can I send an email to more than one user via command line once the process of downloading these files are over?
You can use keys in order to avoid scp asking password. The procedure in two words is to create a public and private key and copy the public key to the remote machine in the ~/.ssh directory.
Now, about how you can send an email with multiple recipients, that depends what MTA is available on your machine. Just check the man pages or look it up.
Here's an example of sending mail in bash. You just need to put a loop around it and feed in a list of email addresses eg from a file
usr1@somewhere
usr2@somewhereelse
etc http://theos.in/shell-scripting/send-mail-bash-script/
i would prefere getting ssh or https access rather than http if security was my concern
for scp you can have public key logins (see man page for ssh/scp command line option -i)
also perhaps look at ssh-agent
Sorry, what I meant to say was HTTPS and not HTTP.
I read up a bit about SCP and the identity file, it seems as though this will create two key files and one has to be placed in the remote server? The thing is, I can only read from the remote server, I don't have the authority to write anything to it.
It looks as though HTTPS is my next safest bet, right?
One more thing, assuming I do go with SCP, what if the file I'm attempting to access does not exist one day, can I get some soft of signal that will indicate this so that I can halt the rest of the processes that depend on the existence of this file?
Quote:
Originally Posted by chrism01
Here's an example of sending mail in bash. You just need to put a loop around it and feed in a list of email addresses eg from a file
usr1@somewhere
usr2@somewhereelse
etc http://theos.in/shell-scripting/send-mail-bash-script/
Thanks, so there's no way to send an email to multiple users using the `mail` command in one go without using a loop?
I googled a bit and found that the following ways will also work to send emails:
Code:
mail -s "My Subject" user@example.org < /path/to/message/body
echo "My message body." | mail -s "My Subject" user@example.org
How would I loop to include multiple emails? I'm relatively new to shell scripting.
In re your last, make 'user' a bash var and assign to it in a loop, somehting like
Code:
for user in 'a b c d e'
do
mail -s "My Subject" ${user}@example.org < /path/to/message/body
or
echo "My message body." | mail -s "My Subject" ${user}@example.org
done
In re your last, make 'user' a bash var and assign to it in a loop, somehting like
Code:
for user in 'a b c d e'
do
mail -s "My Subject" ${user}@example.org < /path/to/message/body
or
echo "My message body." | mail -s "My Subject" ${user}@example.org
done
You really ned to read those links I gave you, it'll be quicker than posting qns (although come back if you really get stuck).
There are many ways of generating/using lists, but explicit arrays are explained here: http://www.tldp.org/LDP/abs/html/arrays.html
You really ned to read those links I gave you, it'll be quicker than posting qns (although come back if you really get stuck).
There are many ways of generating/using lists, but explicit arrays are explained here: http://www.tldp.org/LDP/abs/html/arrays.html
well i have been reading a few bash tutorials over the past week or more but i wanted to know if using an array is the best way because there are usually more than one way to do things. i just wanted to know which was best.
I have another problem that I'm not sure how to solve because I don't know what to look for:
Code:
file_exists () {
# if file doesn't exist, email with custom mail parameters else, return.
# $1 = the file
# $2 = subject
# $3 = message (can be file or text)
# $4 = list of email addresses to send to
if [ ! -f $1 ]; then
if [ ! -f $3 ]; then
for user_email in $4
do
echo $3 | mail -s $2 ${user_email}@example.org
done
else
for user_email in $4
do
mail -s $2 ${user_email}@example.org < $3
done
fi
else
return
fi
}
file_exists "/path/to/file" "File missing" "The required file does not exist." ${ADMIN_EMAILS}
I want to send an email either with an existing template file as the body text or using the input as the body text, depending on how I input my parameters. But when I run this command, it tells me there are too many parameters...I'm guessing this is because it tries to stat the $3 argument which won't be possible if it's a string input with spaces in it.
How can I work around this? At least tell me what to look for.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.