How would you upload an artifact using powershell?
The following works with bash
ARTIFACT_MD5_CHECKSUM=$(md5sum /tmp/bar.zip | awk '{print $1}')
ARTIFACT_SHA1_CHECKSUM=$(shasum -a 1 /tmp/bar.zip | awk '{ print $1 }')
curl --upload-file "/tmp/bar.zip" --header "X-Checksum-MD5:${ARTIFACT_MD5_CHECKSUM}" --header "X-Checksum-Sha1:${ARTIFACT_SHA1_CHECKSUM}" -u "admin:${ARTIFACTORY_API_KEY}" -v https://artifactory.example.com/artifactory/foo/
Use Invoke-RestMethod
$password = ConvertTo-SecureString -AsPlainText -Force -String '<api_key>'
$cred = New-Object Management.Automation.PSCredential ('admin', $password)
$ARTIFACT_SHA1_CHECKSUM=$(Get-FileHash -Algorithm SHA1 c:\bar.zip).Hash
$HEADERS = #{"X-Checksum-SHA1"=$ARTIFACT_SHA1_CHECKSUM;};
Invoke-RestMethod -Uri https://artifactory.example.com/artifactory/foo/bar.zip -Method PUT -InFile c:\bar.zip -cred $cred -Headers $HEADERS
Including the SHA1 hash as part of the headers is optional.
Make sure:
use 'PUT' not 'POST'
filename must be part of the URI
Sha256 checksums can't currently be uploaded, instead their calculation needs to be requested through the api.
$CONTENT = #{"repoKey"="nd-web-zips";"path"=$localFile} | ConvertTo-Json
# For some reason, the api doesn't like $cred, pass the api key in directly to the headers
$HEADERS2 = #{"X-JFrog-Art-Api"=$APIKEY}
Invoke-RestMethod -Uri https://artifactory.example.com/artifactory/api/checksum/sha256 -Method POST -Body $CONTENT -ContentType "application/json" -Headers $HEADERS2
Related
I am trying to send a mail with zip file attached from an unix box. I am limited to use sendmail utility. i ziped the files using the command
zip test.zip 1.html 2.html 3.html
and when trying to send mail with below commands. One of the three files (first file) is not opening properly. but the rest 2.html and 3.html is working fine.
I am getting the error as "Unavailable Data: 1.html"
(
echo "From: from#from.com"
echo "To: to#to.com"
echo "Subject: subject"
echo "Mime-Version: 1.0"
echo 'Content-Type: multipart/mixed; boundary="X12345"'
echo '--X12345'
echo "Content-Type: application/zip;"
echo "Content-Transfer-Encoding: base64"
echo "Content-Disposition: attachement; filename=test.zip"
base64 test.zip
echo '--X12345'
) | sendmail -t
Can some please help. Thanks in advance.
You failed to provide empty line to mark end of main headers and end of mime part header.
(
cat - <<END
From: from#from.com
To: to#to.com
ubject: subject
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="X12345"
--X12345
Content-Type: application/zip;
Content-Transfer-Encoding: base64
Content-Disposition: attachement; filename=test.zip
END
base64 test.zip
echo '--X12345'
) | /usr/sbin/sendmail -t
I am trying to send a mail via UNIX with HTML body and xlsx file as attachment, but I am not able to attach the file with the mail, can anybody share some sample code? This is what I have tried, I have to send the XLSX file as attachment for simplicity I am trying it with CSV,
Unix var file is a CSV file which contains data as abc,xyz#gmail.com
echo $file
while read LINE
do
echo $LINE;
fund_provider_code=`echo $LINE | awk -F',' '{print$1}'`
len=`echo $fund_provider_code | awk '{print length}'`
length=`expr $len + 2`
email_list=`echo $LINE | cut -c $length-`
echo fund_code=$fund_provider_code
email=$email_list
(BOUNDARY='=== This is the boundary between parts of the message. ==='
ATTACHMENT="$attachment_file"
SUBJECT="$subject_text"
VERSION=1.0
print - 'To:' ${email_list}
print - 'Subject:' ${SUBJECT}
print - 'MIME-Version: 1.0'
print - 'Content-Type: MULTIPART/MIXED; '
print - 'Content-Type: TEXT/HTML; charset=US-ASCII'
print -
awk -v message1="${msg1}" ' BEGIN {
print "<html><body>"
print "<style>"
print "p.MsoNormal, li.MsoNormal, div.MsoNormal \{mso-style-parent:\"\"; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt;font-family:\"Arial\"; mso-fareast-font-family:\"MSMincho\";\}"
print "</style>"
print "<div class=Section1>"
print "<p class=MsoNormal style=\"mso-layout-grid-align:none;text-autospace:none\"><span style=\"font-size:12.0pt;font-family:'Arial';mso-bidi-font-family:'Arial'; color:Black\">Dear All,<o:p></o:p></span></p>"
print "</div></body></html>"
}' email_body.txt;
print -
print - "--${BOUNDARY}--"
print - 'ATTACH="/projects/dit/edw/EDW_OUTBOUND_FEEDS/bin/email.csv"'
print - 'Content-Type: TEXT/HTML, multipart/mixed, text/html, application/octet-stream ; name=email.csv'
print - "Content-Transfer-Encoding: base64"
print - 'Content-Disposition: attachment; filename=abc.csv'
uuencode "/projects/dit/edw/EDW_OUTBOUND_FEEDS/bin/email.csv" email.csv
print -
print - "--${BOUNDARY}--"
) | sendmail ${email_list}
done < "$file"
It looks like you have a discrepancy in the filename you want to send. The below assume you want to send file locally defined as:
/projects/dit/edw/EDW_OUTBOUND_FEEDS/bin/email.csv
--- however, you hadn't defined it properly, so I fixed the assignment so:
ATTACH="/projects/dit/edw/EDW_OUTBOUND_FEEDS/bin/email.csv"
Or did you want to use ATTACHMENT? I think you must clean this code.
I found no use of this line:
ATTACHMENT="$attachment_file"
var subject_text isn't defined, or is it in a part of the script we don't see in your OP?
var attachment_file isn't defined either.
I think you should use the file you want to send in a var: $ATTACH
echo $file
while read LINE
do
echo $LINE;
fund_provider_code=`echo $LINE | awk -F',' '{print$1}'`
len=`echo $fund_provider_code | awk '{print length}'`
length=`expr $len + 2`
email_list=`echo $LINE | cut -c $length-`
echo fund_code=$fund_provider_code
email=$email_list
(BOUNDARY='=== This is the boundary between parts of the message. ==='
ATTACHMENT="$attachment_file"
ATTACH="/projects/dit/edw/EDW_OUTBOUND_FEEDS/bin/email.csv"
SUBJECT="$subject_text"
VERSION=1.0
print - 'To:' ${email_list}
print - 'Subject:' ${SUBJECT}
print - 'MIME-Version: 1.0'
print - 'Content-Type: MULTIPART/MIXED; '
print - 'Content-Type: TEXT/HTML; charset=US-ASCII'
print -
awk -v message1="${msg1}" ' BEGIN {
print "<html><body>"
print "<style>"
print "p.MsoNormal, li.MsoNormal, div.MsoNormal \{mso-style-parent:\"\"; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt;font-family:\"Arial\"; mso-fareast-font-family:\"MSMincho\";\}"
print "</style>"
print "<div class=Section1>"
print "<p class=MsoNormal style=\"mso-layout-grid-align:none;text-autospace:none\"><span style=\"font-size:12.0pt;font-family:'Arial';mso-bidi-font-family:'Arial'; color:Black\">Dear All,<o:p></o:p></span></p>"
print "</div></body></html>"
}' email_body.txt;
print -
print - "--${BOUNDARY}--"
print - 'ATTACH="${ATTACH}"'
print - 'Content-Type: TEXT/HTML, multipart/mixed, text/html, application/octet-stream ; name="'$(basename ${ATTACH})'"'
print - "Content-Transfer-Encoding: base64"
print - 'Content-Disposition: attachment; filename="'$(basename ${ATTACH})'"'
uuencode $ATTACH $(basename ${ATTACH})
print - "--${BOUNDARY}--"
) | sendmail ${email_list}
done < "$file"
From examples I saw, if you use GNU uuencode, you may need to replace the line
uuencode $ATTACH $(basename $ATTACH)
by
uuencode --base64 $ATTACH $(basename $ATTACH)
I am trying to add a custom metric to ceilometer via API and have success in adding new metric and new data, but I have fail when try to see this new metric in dashboard.
The comand I gave use:
Get a token:
curl -i -X POST http://controller:35357/v2.0/tokens -H "Content-Type: application/json" -H "User-Agent: python-keystoneclient" -d '{"auth": {"tenantName": "test", "passwordCredentials": {"username": "admin", "password": "password"}}}' ;
Take token:
mysql -e 'use keystone; select id from token;' | tail -n 1
Add custom metric with data:
curl -X POST -H 'X-Auth-Token: TOKEN' -H 'Content-Type: application/json' -d '[{"counter_name": "test","user_id": "admin_user_id","resource_id": "Virtual_machine_ID","resource_metadata": {"display_name": "my_test","my_custom_metadata_1": "value1","my_custom_metadata_2": "value2"},"counter_unit": "%","counter_volume": 10.57762938230384,"project_id": "VM_tenant_ID","counter_type": "gauge"}]' http://controller:8777/v2/meters/test
All of that comands have success =)
Checking with comands like:
ceilometer sample-list -m test
ceilometer meter-list |grep test
ceilometer statistics -m test
they are returns the data that I have input before. But when I am open dashboard with Resources Usage Overview I can't see new metric in a list.
So I can't found a desicion of my problem. Anybody can help me?
How can I send an email through the UNIX mailx command?
an example
$ echo "something" | mailx -s "subject" recipient#somewhere.com
to send attachment
$ uuencode file file | mailx -s "subject" recipient#somewhere.com
and to send attachment AND write the message body
$ (echo "something\n" ; uuencode file file) | mailx -s "subject" recipient#somewhere.com
Here you are :
echo "Body" | mailx -r "FROM_EMAIL" -s "SUBJECT" "To_EMAIL"
PS. Body and subject should be kept within double quotes.
Remove quotes from FROM_EMAIL and To_EMAIL while substituting email addresses.
mailx -s "subjec_of_mail" abc#domail.com < file_name
through mailx utility we can send a file from unix to mail server.
here in above code we can see
first parameter is -s "subject of mail"
the second parameter is mail ID and the last parameter is name of file which we want to attach
mail [-s subject] [-c ccaddress] [-b bccaddress] toaddress
-c and -b are optional.
-s : Specify subject;if subject contains spaces, use quotes.
-c : Send carbon copies to list of users seperated by comma.
-b : Send blind carbon copies to list of users seperated by comma.
Hope my answer clarifies your doubt.
Its faster with MUTT command
echo "Body Of the Email" | mutt -a "File_Attachment.csv" -s "Daily Report for $(date)" -c cc_mail#g.com to_mail#g.com -y
-c email cc list
-s subject list
-y to send the mail
From the man page:
Sending mail
To send a message to one or more people, mailx can be invoked with
arguments which are the names of
people to whom the mail will be sent.
The user is then expected to type in
his message, followed
by an ‘control-D’ at the beginning of a line.
In other words, mailx reads the content to send from standard input and can be redirected to like normal. E.g.:
ls -l $HOME | mailx -s "The content of my home directory" someone#email.adr
echo "Sending emails ..."
NOW=$(date +"%F %H:%M")
echo $NOW " Running service" >> open_files.log
header=`echo "Service Restarting: " $NOW`
mail -s "$header" abc.xyz#google.com, \
cde.mno#yahoo.com, \ < open_files.log
Customizing FROM address
MESSAGE="SOME MESSAGE"
SUBJECT="SOME SUBJECT"
TOADDR="u#u.com"
FROM="DONOTREPLY"
echo $MESSAGE | mail -s "$SUBJECT" $TOADDR -- -f $FROM
Here is a multifunctional function to tackle mail sending with several attachments:
enviaremail() {
values=$(echo "$#" | tr -d '\n')
listargs=()
listargs+=($values)
heirloom-mailx $( attachment=""
for (( a = 5; a < ${#listargs[#]}; a++ )); do
attachment=$(echo "-a ${listargs[a]} ")
echo "${attachment}"
done) -v -s "${titulo}" \
-S smtp-use-starttls \
-S ssl-verify=ignore \
-S smtp-auth=login \
-S smtp=smtp://$1 \
-S from="${2}" \
-S smtp-auth-user=$3 \
-S smtp-auth-password=$4 \
-S ssl-verify=ignore \
$5 < ${cuerpo}
}
function call:
enviaremail "smtp.mailserver:port" "from_address" "authuser" "'pass'" "destination" "list of attachments separated by space"
Note: Remove the double quotes in the call
In addition please remember to define externally the $titulo (subject) and $cuerpo (body) of the email prior to using the function
If you want to send more than two person or DL :
echo "Message Body" | mailx -s "Message Title" -r sender#someone.com receiver1#someone.com,receiver_dl#.com
here:
-s = subject or mail title
-r = sender mail or DL
I want to post XML data with cURL. I don't care about forms like said in How do I make a post request with curl.
I want to post XML content to some webservice using cURL command line interface. Something like:
curl -H "text/xml" -d "<XmlContainer xmlns='sads'..." http://myapiurl.com/service.svc/
The above sample however cannot be processed by the service.
Reference example in C#:
WebRequest req = HttpWebRequest.Create("http://myapiurl.com/service.svc/");
req.Method = "POST";
req.ContentType = "text/xml";
using(Stream s = req.GetRequestStream())
{
using (StreamWriter sw = new StreamWriter(s))
sw.Write(myXMLcontent);
}
using (Stream s = req.GetResponse().GetResponseStream())
{
using (StreamReader sr = new StreamReader(s))
MessageBox.Show(sr.ReadToEnd());
}
-H "text/xml" isn't a valid header. You need to provide the full header:
-H "Content-Type: text/xml"
I prefer the following command-line options:
cat req.xml | curl -X POST -H 'Content-type: text/xml' -d #- http://www.example.com
or
curl -X POST -H 'Content-type: text/xml' -d #req.xml http://www.example.com
or
curl -X POST -H 'Content-type: text/xml' -d '<XML>data</XML>' http://www.example.com
It is simpler to use a file (req.xml in my case) with content you want to send -- like this:
curl -H "Content-Type: text/xml" -d #req.xml -X POST http://localhost/asdf
You should consider using type 'application/xml', too (differences explained here)
Alternatively, without needing making curl actually read the file, you can use cat to spit the file into the stdout and make curl to read from stdout like this:
cat req.xml | curl -H "Content-Type: text/xml" -d #- -X POST http://localhost/asdf
Both examples should produce identical service output.
Have you tried url-encoding the data ? cURL can take care of that for you :
curl -H "Content-type: text/xml" --data-urlencode "<XmlContainer xmlns='sads'..." http://myapiurl.com/service.svc/
You can try the following solution:
curl -v -X POST -d #payload.xml https://<API Path> -k -H "Content-Type: application/xml;charset=utf-8"