Skip to main content

Run scripts on start up in Linux

There are different ways to automatically run commands:

1. The upstart system will execute all scripts from which it finds a configuration in directory /etc/init. These scripts will run during system startup (or in response to certain events, e.g., a shutdown request) and so are the place to run commands that do not interact with the user; all servers are started using this mechanism.

You can find a readable introduction to at: http://upstart.ubuntu.com/getting-started.html the man pages man 5 init and man 8 init give you the full details.

2. A shell script named .gnomerc in your home directory is automatically sourced each time you log in to a GNOME session. You can put arbitrary commands in there; environment variables that you set in this script will be seen by any program that you run in your session.

Note that the session does not start until the .gnomerc script is finished; therefore, if you want to autostart some long-running program, you need to append & to the program invocation, in order to detach it from the running shell.

3. The menu option System -> Preferences -> Startup Applications allows you to define what applications should be started when your graphical session starts (Ubuntu predefines quite some), and add or remove them to your taste. This has almost the same purpose and scope of the .gnomerc script, except you don't need to know sh syntax (but neither can you use any shprogramming construct).

 4. One approach is to add an @reboot cron task:

Running crontab -e will allow you to edit your cron.
Adding a line like this to it:

@reboot /path/to/script

will execute that script once your computer boots up.

Comments

Popular posts from this blog

JSON (JavaScript Object Notation)

JSON (JavaScript Object Notation) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays (or other serializable values). It is a common data format with diverse uses in electronic data interchange, including that of web applications with servers. JSON is a language-independent data format. It was derived from JavaScript, but many modern programming languages include code to generate and parse JSON-format data. JSON filenames use the extension .json. Any valid JSON file is a valid JavaScript (.js) file, even though it makes no changes to a web page on its own. Douglas Crockford originally specified the JSON format in the early 2000s. He and Chip Morningstar sent the first JSON message in April 2001. Official website :- https://json.org/

Object serialization in java

Serialization is the conversion of an object to a series of bytes, so that the object can be easily saved to persistent storage or streamed across a communication link. The byte stream can then be deserialized - converted into a replica of the original object. When you want to serialize an object, that respective class should implement the marker interface serializable. It just informs the compiler that this java class can be serialized. You can tag properties that should not be serialized as transient. You open a stream and write the object into it. Code for serialization of a java class : Data.java package com . codetalk . serialization ; import java.io.Serializable ; public class Data implements Serializable { private static final long serialVersionUID = 1L; private String firstName ; private String lastName ; /** * @return the firstName */ public String getFirstName () { return firstName ; } /** * @param firstNam

Amazon Lambda (AWS Lambda)

 AWS Lambda is an event-driven, serverless computing platform provided by Amazon as a part of Amazon Web Services. It is a computing service that runs code in response to events and automatically manages the computing resources required by that code. It was introduced on November 13, 2014. AWS Lambda was designed for use cases such as image or object uploads to Amazon S3, updates to DynamoDB tables, responding to website clicks, or reacting to sensor readings from an IoT connected device.  Unlike Amazon EC2, which is priced by the hour but metered by the second, AWS Lambda is metered by rounding up to the nearest millisecond with no minimum execution time. AWS Lambda can also be used to automatically provision back-end services triggered by custom HTTP requests, and "spin down" such services when not in use, to save resources. Since December 2020 Lambda supports Docker containers through ECR up to 10 GB in size. Official website :- https://aws.amazon.com/lambda