How to log out and back in using a bash script

1

I am trying to set ulimit when starting an EC2 instance on Amazon Web Services.

Is there any way to write a script that will:

  1. sudo root to set ulimit, then:
  2. Log out and back in as my original user in order to run some commands?

Jiang Xiang

Posted 2015-03-23T23:44:42.737

Reputation: 115

Question was closed 2015-03-29T10:03:09.263

Answers

1

  1. Increase ulimit in /etc/security/limits.conf or by executing sudo ulimit -n number_of_files
  2. Open a new login shell by typing either ssh localhost or su - username

hBy2Py

Posted 2015-03-23T23:44:42.737

Reputation: 2 123

It works interactively, but when I put the following into a script, it does not work well. Here is my script: `sudo bash

ulimit -n 1000000 su - hadoop` – Jiang Xiang – 2015-03-24T00:01:45.977

Can you provide more clarity about exactly what you're trying to do? Are you testing different values of ulimit? Do you just want ulimit to be set to a given value every time you log in? – hBy2Py – 2015-03-24T00:08:05.727

I am starting a new EC2 instance every time I run the script. So that I am not able to set ulimit manually. I do want ulimit to be set to a given value every time I log in. – Jiang Xiang – 2015-03-24T00:09:20.817

1

Ah, so really what you want to be able to do, I think, is to customize limits.conf (http://ss64.com/bash/limits.conf.html) for each new instance you spin up. That's an AWS question, and I have no experience there. You may want to edit your question to be more general, to clarify this.

– hBy2Py – 2015-03-24T00:14:55.283

Googling a bit, I found another possibility. See my edit. Also, in your particular script, you probably need to put a semicolon in there to break up the commands: sudo bash ulimit -n 1000000; su - hadoop or sudo bash ulimit -n 1000000; ssh localhost. – hBy2Py – 2015-03-24T00:20:38.837