Posts

AWS CLI Script to list all the EC2 Servers in all AWS Accounts in all Regions

  To list all EC2 servers across all AWS accounts and regions using AWS CLI, you can use the aws command with the ec2 describe-instances option and specify the --profile and --region options for each account and region. Here's an example command that you can use as a starting point: #!/bin/bash # List of AWS accounts and regions accounts=("account1" "account2") regions=("us-east-1" "us-west-2" "eu-west-1") # Loop through the accounts and regions for account in "${accounts[@]}" do for region in "${regions[@]}" do # Set the profile and region export AWS_PROFILE=$account export AWS_DEFAULT_REGION=$region # Get the EC2 instances in the region instances=$(aws ec2 describe-instances --query 'Reservations[].Instances[].InstanceId' --output text) # Print the instances echo "Instances in $account - $region:" echo "$instances" done done In this scrip

Linux : Special permissions to users for file & directories using "setfacl"

  To set special permissions to users for files and directories using the "setfacl" command in Linux, you can follow these steps: Install the "acl" package if it is not already installed on your system. You can do this using your distribution's package manager, such as apt, yum, or pacman. For example, on Ubuntu or Debian, you can run the following command: sudo apt-get install acl Check the current ACL settings of the file or directory you want to modify by using the "getfacl" command. For example, to check the ACL settings of a file called "example.txt", you can run the following command: getfacl example.txt This will show you the current permissions and access control entries (ACEs) for the file. Use the "setfacl" command to add or modify the ACEs for the file or directory. The basic syntax of the "setfacl" command is as follows: ruby setfacl -m user: <username> :<permissions> <file/directory> In this

Linux : Port Numbers for common services

 Below are some of the default port numbers in Linux SSH (Secure Shell) - port 22 FTP (File Transfer Protocol) - port 20 (data) and port 21 (control) HTTP (Hypertext Transfer Protocol) - port 80 HTTPS (HTTP over SSL/TLS) - port 443 DNS (Domain Name System) - port 53 SMTP (Simple Mail Transfer Protocol) - port 25 POP3 (Post Office Protocol version 3) - port 110 IMAP (Internet Message Access Protocol) - port 143 NFS (Network File System) - port 2049 Samba (Windows file sharing) - port 137-139 and 445 Note that these are the default port numbers for these services, but they can be configured to use different ports if needed. Also, some services may use multiple ports depending on their configuration.

Linux : Difference between /etc/hosts and /etc/resolv.conf

There are basic files to check for when we get any network related issues, Permissions of these files are very important, even if all the entries are correct, hostnames will not resolve and gives an error no host name found. Read permission is a must to resolve network issues if everything else is correct.   /etc/resolv.conf : Lists nameservers that are used by your host for DNS resolution. If you are using  DHCP , this file is automatically populated with DNS records issued by  DHCP  server. /etc/hosts/ : It is just a static lookup method for resolution. /etc/nsswitch.con f: It defined the order of resolution. Who should it consult first for resolution, a DNS or a host file? For example, if the file has the following configuration  hosts: files dns  then  /etc/hosts  the file will be checked first for resolution, if the domain is still un-resolvable, DNS will then be consulted.

Useful Linux Commands

Here are some useful Linux commands which are useful, It will be updated frequently -  Restart VMware tools /etc/vmware-tools/services.sh restart   Reset user account with failed login attempts pam_tally2 --user=username --reset pam_tally2 -r -u username Start date and time of a linux process ps - eo pid,lstart,cmd TSM backup client status, start, stop, restart # service dsmcad start # service dsmcad stop # service dsmcad restart # service dsmcad statis TSM client home dir. /opt/tivoli/tsm/client/ba/bin/ Top files using high space in current directory  find . -xdev -type f -size +100M -exec du -sh {} ';' | sort -rh | head -n50 Compress a file using gzip gzip -c logfile > /tmp/logfile.gz && > logfile SUSE linux fs extend lvextend -L +1G /dev/mapper/system-lvopt # resize_reiserfs -f /dev/vg01/lvol1 or for btrfs btrfs filesystem resize max /opt # umount /dev/vg01/lvol1 # resize_reiserfs /dev/vg01/lvol1 # mount -treiserfs /dev/vg01/lvol1