Script and Cronjob Help

Nope, I caught it.
Was typing my response while you typed that up.
It’s ok.

Well, another point about that script.
When I ran it, the directory and all inside the directory are being created with “root” as the owner and group.
I would then have to regain ownership and permissions every time.
That can get annoying.

I would like to not have to regain that which should be automatically granted to me.
And yes, I would like for all in the script to be directed to my yahoo or gmail or…yeah.
I’m gonna try to create a filter in yahoo mail to have yahoo put these files into a folder automatically.
Then later, I may use the gmail for this to keep things seperate from all other email to my yahoo, at least for now.

Ok, in that case I think that the best approach is to zip all the files from that folder and sent that zip file to your email.

So just insert these lines at the end of your script, replacing the xxxxxxxx@zzzzz.com with your email (gmail, yahoo, whatever…) in the 2nd line:

printf "From: `hostname` <root@`hostname`>\n\
To: xxxxxxxx@zzzzz.com\n\
Subject: Reports\n\
Mime-Version: 1.0\n\
Content-Type: multipart/mixed; boundary=A1234567890\n\n\
--A1234567890\n\
Content-Type: text/plain\n\
Content-Disposition: inline\n\n\
Attached file "reports.zip".\n\n\
--A1234567890\n\
Content-Type: application/zip\n\
Content-Transfer-Encoding: base64\n\
Content-Disposition: attachment; filename="reports.zip"\n\n\
`zip - /home/wyatt/Desktop/System-Reports/* | base64`\n\n\
--A1234567890" | sendmail

Run your script and you should receive an email with the reports.zip file.

Then, just remove the redirection from your command in the crontab. It should be:
43 11 * * * /home/wyatt/Desktop/System-Reports.sh

Also, if you want to use gmail account change it in file /etc/nullmailer/adminaddr as it contains the yahoo one.

And that’s all.

Just change the ownership of the folder and all it’s files at the end of the script. Something like this:

chown -R wyatt:wyatt /home/wyatt/Desktop/System-Reports/

One last thing: be warned that your system is now ready to send emails so there may be some emails, usually related to security appplications, that you will receive in your email account. It’s up to you to decide if you want to keep these emails enabled or not.

Please explain more about keeping the emails enabled or not.

I mean that when you receive that kind of email you may be interested or not. So you may decide if leave it enabled or not.

An example; if any user try sudo command and insert an incorrect password 3 times it will generate an email to warn you as root user (I’m not sure if you will receive it in your gmail or yahoo).
If you don’t want that email you will disable it in the file /etc/sudoers.

Additionally, to avoid that, you can disable the nullmailer.service and only enable+start it in your script before sending the email and stop+disable it after the email was sent. So it will be used only in your script.

Sounds like something I need to do exactly and correctly.

What needs to be there and where does it need to be in the sudoers files?

and…

I’ve never done that before.
What needs to be in the script and exactly where does each one need to be put?

It was just an example, not mandatory at all.

First test that the current setup works for your needs. This was only an example of what you can do if you really, really don’t want to leave nullmailer active for other applications than your script, but is not needed for now.

Oh ok

I don’t use bluetooth so I disable it and if I ever need it I enable+start bluetooth only for the current session.

Using the same outline, I did a small test with disabling the nullmailer.service and put in the commands to enable+start before sending mail and stop+disable after the mail is sent. Then set the crontab entry to run the script soon after. It didn’t work. So I changed it back to the way it was.

For now, I think keeping it enabled is best for me.

Let me throw another ball.

There is a tool named Actiona in repo.

If you install through Synaptic (search actiona) and launch this you can write actions in a GUI.

Dating back to days of ActionScript (I still have the O’Reilly book authored by Colin Mook circa 2000 - ActionScript: The Definitive Guide).

From the Flash era.

For example capture log files.

There is an Object send Email in the data section.

So the idea is …

create a Procedure to capture logs

create a Procedure to send email via an SMTP server.

Once you have tested your script manually through GUI you can trigger the Actiona script … such as LogSend.ascr … using the command … actexec LogSend.ascr.

This could be triggered by cron.

Actiona is handy for a host of automation tasks.

Not sure if you’re @dragonfly on ubuntuforums.org.

He/She was working with me on a project I was trying to do using actiona.
I couldn’t get the hang of it.

I believe I let him/her know that I was just not catching on and so I felt comfy not using actiona.

Thanks for the suggestion though.

Yes, in a previous encarnation I was @dragonfly41 in Ubuntu Forums. I couldn’t figure out how to carry my old alias into this new world. And I’m an octogenarian male still dabbling.

It might be the case that some CLI advocates are not interested in Actiona GUI. It is of French development origin and I think stemming from games UI automation. It is rather old as I indicated and based on Qt4 (current Qt version is 6) . Here is the source.

Refer to the various links.

I learned the ropes by reading this old forum. Most of the action is in the French section (the developer is French) and I just switch on Google translator to follow ideas.

There are some real hidden gems (e.g. Open CV) if you persist and don’t drop it at first glance.

For example you can write scripts to drive third party complex UI’s - remote driving of complex interfaces - however complex.

In your case you might create a dropdown menu of logs you wish to send - or other rules or actions.

If I find time I will try to knock together an example *.ascr script (that stands for actionscript2).

One downside is that the internal code editor font is too tiny for my weary eyes and so I develop code outside in say Sublime Text and then paste into code editor or include. there is a Sublime Text Actionscript2 syntax package. But also in other editors such as VSCode (I used Electron Atom until GitHub sunset Atom editor).

Resources such as Python scripts et al can also be added. So although old it is a Swiss Army knife.

In a complex UI such as say Blender (as one example) if you capture in advance the x,y coordinates or images of UI touchpoints in a JS array you can use Actiona as an eLearning tool for remote coaching. Sure beats trying to follow YouTube tutorials with tiny screenshots.

@dl or dragonfly…i think dragonfly is easiest for me to remember.

It sure is a comfort knowing that another one who has so helped a lot of ppl (including helping me) is here on Discourse. And it is for sure a new learning curve. But I’m catching on to discourse faster than I expected.

I’m glad to inform you that I’ve learned how to get a cronjob goin. It’s a lot easier than what the various tutorials and manpages made it seem.

About actiona, script automation, and things such as imvu and blender…
I’m working on the cronjobs currently to be able to open up some free time for other things. Currently most of my time is spent updating, upgrading, and finding out what not to clean out before deleting everything in important log locations due to things idk about linux. and also system snapshots and backups.

I’m learning how powerful cron is. No mess ups with it yet. (keeps fingers crossed)

What needs to be in the content-type line below to include “.txt" ".log”, ".crash", and the files in /var/log and it’s child directories which have no mime-type in the filename?
(
.txt is already there.)

printf "From: `hostname` <root@`hostname`>\n\
To: xxxxxxxx@zzzzz.com\n\
Subject: Reports\n\
Mime-Version: 1.0\n\
Content-Type: multipart/mixed; boundary=A1234567890\n\n\
--A1234567890\n\
Content-Type: text/plain\n\
Content-Disposition: inline\n\n\
Attached file "reports.zip".\n\n\
--A1234567890\n\
Content-Type: application/zip\n\
Content-Transfer-Encoding: base64\n\
Content-Disposition: attachment; filename="reports.zip"\n\n\
`zip - /home/wyatt/Desktop/System-Reports/* | base64`\n\n\
--A1234567890" | sendmail

The extension of a file isn’t mandatory in linux so it’s not the best way to know the type of it’s content. You should use the command file -b --mime-type FILE. I.e.:

$ file -b --mime-type /var/crash/_usr_bin_evince.1026.crash
text/plain

But, as I stated in previous posts, the best way to send via email several files is to zip them all in an unique zip file and sent that zip file by email encoded in base64, just as we did with the “reports.zip”. So you don’t need to know the Content-Type of the files inside the zip file.

Um…where does that go in the script?
Or will it zip them no matter what mime-type is specified?
In which I would use a command to just move the files to the System-Reports directory.

Not for the script. It’s the way to know the Content-Type of a file, as you asked.

Exactly.

Yes, but you should copy the files instead of move them.

Post 1 wasn’t trying to ask in several seperate questions.
I was trying to cover a complete idea in asking my question.
When I asked my original question, I was thinking, “what if it isn’t for the script”

That’s good to know, thank you.

That’s an idea, thank you.
What’s the command line to copy a file?
I know the “find” “xargs” and “mv” command.
I prefer to use commands for the terminal (not the current working directory)
(there i go again…the complete idea thing)
(that looks like I believe the working directory isnt part of terminal use)
Here’s how I prefer…
Have nothing open except a terminal, run the command, and get the work done.
Don’t waste time opening the directory to run a command.
Get the work done.

The command is cp. It’s syntax is similar to the mv command you know and, as it’s a basic command, you will find tons of usage examples all over internet.

Ok, the emails to my yahoo are working, but with each one I’m getting this message in my gmail.
Is it something I should worry about?

Address not found
Your message wasn't delivered to root@wyatt-aspiree1532.wyatt-aspiree1532 because the domain wyatt-aspiree1532.wyatt-aspiree1532 couldn't be found. Check for typos or unnecessary spaces and try again.

That’s a bounce email. Some application is trying to sent an email to an incorrect address.

Probably nothing to worry about. You can try to find what’s the application that is sending the email looking at the info attached to the email and the “From” field and disable its sent.

Considering this part of the script…

printf "From: `hostname` <root@`hostname`>\n\

And this part of the email to gmail…

Address not found
Your message wasn't delivered to root@wyatt-aspiree1532.wyatt-aspiree1532 because the domain wyatt-aspiree1532.wyatt-aspiree1532 couldn't be found. Check for typos or unnecessary spaces and try again.

the “root@…” part of the script seem’s to suggest that something within nullmailer is causing this.
Most likely it’s a minor thing since the email’s to yahoo is working.