use the content of a file as subject mailx - awk

i need to send a weekly email containing some dynamic information that will be collected in a txt file. what i can't accomplish is adding the content of that file into the subject of my email.
my file is named bkp.txt and has one line "weekly backups; total: 10; size: 3gb"
is there any way i can send an email using this format
mailx -s "weekly backups; total: 10; size: 3gb" "email.address#domain.com" < another.txt, keeping in mind the content of bkp txt can modidy every week?
thanks!

Use bash command substitution:
mailx -s "$(<bkp.txt)" ......

Related

Add file name and timestamp into each record in BigQuery using Dataflow

I have a few .txt files with data in JSON to be loaded to google BigQuery table. Along with the columns in the text files I will need to insert filename and current timestamp for each rows. It is in GCP Dataflow with Python 3.7
I accessed the Filemetadata containing the filepath and size using GCSFileSystem.match and metadata_list.
I believe I need to get the pipeline code to run in a loop, pass the filepath to ReadFromText, and call a FileNameReadFunction ParDo.
(p
| "read from file" >> ReadFromText(known_args.input)
| "parse" >> beam.Map(json.loads)
| "Add FileName" >> beam.ParDo(AddFilenamesFn(), GCSFilePath)
| "WriteToBigQuery" >> beam.io.WriteToBigQuery(known_args.output,
write_disposition=beam.io.BigQueryDisposition.WRITE_APPEND)
)
I followed the steps in Dataflow/apache beam - how to access current filename when passing in pattern? but I can't make it quite work.
Any help is appreciated.
You can use textio.ReadFromTextWithFilename instead of ReadFromText. That will produce a PCollection of (filename,line) tuples.
To include the file and timestamp in your output json record, you could change your "parse" line to
| "parse" >> beam.map(lambda (file, line): {
**json.loads(line),
"filename": file,
"timestamp": datetime.now()})

Send email using content of a text file

I'm hope to create a script which looks up a date in a text file and then send an email to the corresponding email address. The text file would be structured something like this:
25/02/2018, blah#email.com
26/02/2018, blue#email.com
etc
This will be run on a Windows 2012 box so ideally i'd like to use powershell. I don't want any reliance on a database so i thought a simple text file that could be searched may be the easiest way. Essentially this will be used to send emails alerts for for certain events with the date being used to sent the email to the correct night duty staff. Need to use a script as some of the apps that I hope to link it to have little to no notification options but they can invoke external scripts.
Any guidance gratefully received.
Thanks,
A
Your question is quite broad; here's the outline of a solution (run as a script file, PSv3+):
# Declare a parameter for the target date.
param(
[datetime] $TargetDate = [datetime]::Today
)
# Format the target date as a string to match the input file's date format.
$targetDateFormatted = (Get-Date -Date $TargetDate -Format 'dd/MM/yyyy')
# Specify the input file (CSV format, as implied by your sample data).
$inputFile = 'DateEmail.csv'
Import-Csv -Header Date, Email $inputFile |
Where-Object Date -eq $targetDateFormatted |
ForEach-Object {
Write-Verbose -Verbose "Date is $($_.Date); email address is $($_.Email)"
# Invoke the Send-MailMessage cmdlet here.
}

Creating scripts for obtaining data from a text file

I have a text file named stat.txt which contains lines each in the format
<User Name>-<IP>-<File Name>-<Size>. Each line contains a user name,an IP address,a file name and a download file size.I need to create a script userstat.awk which allows the following data to be obtained when the specific command is written:
userstat.awk u -will list all files
userstat.awk total -will list total size of all files
So far,I have tried to list all the files for a user using default commands but I can't do it using these commands.
Given stat.txt:
user-1.1.1.1-file.jpg-20
root-1.1.1.1-file.jpg-20
user-1.1.1.1-img.jpg-20
root-1.1.1.1-thing.jpg-20
You could use the command (improved by #ClasesWikner):
awk -F- '{print $3; s+=$4}END {print "total: " s}' stat.txt
To output:
file.jpg
file.jpg
img.jpg
thing.jpg
total: 80
As mentioned by #Scheff this will not work when usernames or file names contain a -.

Change in the HTML table format sent using mutt in outlook

Here is my sample html code:
when I send this as an email using mutt to my outlook, the output is as follows:
The command I used is:
mutt -e "my_hdr Content-Type: text/html" -s "Subject: my subject" mymail#outlookmail.com < sampletable.html
In the second table there is some different format. First table is not looking good as well.
If there are more than 2 tables, all the alternate tables are having the same format as second one.
How to make my email look good?
PS: I am generating this sample html table code using awk in a bash script.
Thanks in advance.
replace ending <tr> by closing tr : </tr>.

Reading files using Contiki on MSP430F5438A

I want to read a file from my computer and display it on the board. But we are facing a problem while reading the file as the board is constantly resetting. (The Watchdog is off)
Can anyone help?
Here are the steps to upload a file:
If you want to read a file from your local drive only way to do it by uploading the file into coffee file system (cfs) first than read the file using cfs library such as cfs_open, cfs_seek, and cfs_read as a reference have a look into this link:
https://github.com/contiki-os/contiki/wiki/Coffee-filesystem-guide
Modify the program ".c" file you are working to initialize the base64 and coffee commands in the shell by adding:
shell_base64_init();
shell_coffee_init();
Compile and upload via the command:
make TARGET=platformuaresingnow example.upload
to read/upload .txt file by modifying some bash code. To do so, add the following lines
%.shell-upload: %.txt
``(echo; sleep 4; echo "~K"; sleep 4;``
``echo "dec64 | write $*.txt | null"; sleep 4; \``
``../../tools/base64-encode < $<; sleep 4; ``
`` echo ""; echo "~K"; echo "read $*.txt | size"; sleep 4) | make login``
Now you can upload any .txt file to the coffee filesystem of the currently connected mote node using the command:
make testfile.shell-upload
Hope that it 'll solve your problem.